Here's a simple example provided for MoleKule, a p...
# science
a
# Here's a simple example provided for MoleKule, a package for molecular dynamics!
Copy code
fun main() {

    // a basket for your atoms
    val env = Environment()

    // add to it like any of these methods
    env.add(atomOf(AtomicMass.C, Point(0, 0, 0), 1))
    env.add(H2(Point.randomOrientation * 10))

    // use sequence api to your advantage, or reinvent them yourselves
    Grid3D(20, 20, 20)
        .points
        .map { it * 1.5 } // scale
//        .map { it.rotateZ(45.toRad()) } // rotate
        .map { it + (Point.xHat * 12) } // translate
        .filter { it isInside sphereShape  } // filter
        .map { atomOf(AtomicMass.C, it,1) } // generate
        .forEach { env.add(it) } // add


    
    env.toLammpsInputFile("Hello.data")
    // visualize a bit, it helps
    KoolVisualizer()
        .withDefaultConfig()
        .addPlugin(AxisPlugin())
        .addPlugin(BoxViewerPlugin(env.enclosingBox))
        .init()
        .addEnvironment(env)
        .runAndWaitUntilExit()

}

val sphereShape = Sphere(Point(22,12,12), 10)


class H2(origin: Point) : Molecule(type = 3) {
    init {
        val eps = Point.xHat * 0.3
        val h1 = Atom(origin - eps, AtomicMass.H.mass, 4)
        val h2 = Atom(origin + eps, AtomicMass.H.mass, 4)
        atoms.addAll(listOf(h1, h2))

        // bonds.add()
    }
}
a
Using init blocks for logic is a bad idea. Maybe you should move it to a factory-function?