various solutions for molecular dynamics and related fields using Kotlin Multiplatform
sample code for above screenshop
fun main() {
// your world
val env = Environment()
// read monkey stl
val data = STL(STL::class.java.classLoader.getResource("monkey.stl")!!.readBytes())
val monkeyFace = TriangleMeshClosedSurface(data.triangles)
// sample inside monkey
Grid3D(20, 20, 20)
.points.spanInAllDirections()
.filter { it isInside monkeyFace }
.map { it.rotateX(90.toRad()) }
.map { it.copy(z = -it.z) }
.map { atomOf(AtomicMass.Fe, it) }
.forEach { env.add(it) }
// update box based on monkey face
env.boundingBox = with(env.enclosingBox) {
val edgeLen = listOf(xBoundary.length, yBoundary.length, zBoundary.length).max() * 1.5
Box(-edgeLen to edgeLen, -edgeLen to edgeLen, -edgeLen to edgeLen)
}
// sphere to cut out from
val sphere = Sphere(Point(0, 0, 0), 0.2 * env.enclosingBox.xBoundary.length)
// a famous grid
Grid2D(50, 50)
.points
.spanInAllDirections()
.usingCrystal(Crystal.graphene.armchair(1.0))
.flatMap { listOf(it, it.rotateZ(5.6.toRad())) }
.filter { it isInside env.boundingBox!! }
.filter { it isOutside sphere }
.map { atomOf(AtomicMass.H, it) }
.forEach { env.add(it) }
// visualize
KoolVisualizer()
.withDefaultConfig()
.addPlugin(BoxViewerPlugin(env.enclosingBox))
.init()
.addEnvironment(env)
.runAndWaitUntilExit()
}
run this for yourself from
Name | Description | Platforms |
---|---|---|
molekool-core | base computation for manipulation | |
molekool-visual | minimal embedded visualization tool based on kool-engine | |
molekool-bind | basic integrations with third party tools experimental |
To use this library in your Gradle project, add the following to your build.gradle(.kts)
file:
dependencies {
// Various generators
implementation("io.github.nort3x:molekool-core:$molekoolVersion")
// Using Kool engine to visualize environments
implementation("io.github.nort3x:molekool-visual:$molekoolVersion")
// Basic bindings to various MD third-party tools (experimental)
implementation("io.github.nort3x:molekool-bind:$molekoolVersion")
}
Replace $molekoolVersion
with the latest version of the library.
To use this library in your Maven project, add the following to your pom.xml
file:
<dependencies>
<!-- Various generators -->
<dependency>
<groupId>io.github.nort3x</groupId>
<artifactId>molekool-core</artifactId>
<version>VERSION</version>
</dependency>
<!-- Using Kool engine to visualize environments -->
<dependency>
<groupId>io.github.nort3x</groupId>
<artifactId>molekool-visual</artifactId>
<version>VERSION</version>
</dependency>
<!-- Basic bindings to various MD third-party tools (experimental) -->
<dependency>
<groupId>io.github.nort3x</groupId>
<artifactId>molekool-bind</artifactId>
<version>VERSION</version>
</dependency>
</dependencies>
Replace VERSION
with the latest version of the library.