# generate input xyz based on some parameters import random import os import strutils import strformat import particle import linalg import parsexyz import forces if paramCount() != 3: echo "usage ./genrandom n filename.xyz settingsName" quit 1 let atomCount = parseInt(paramStr(1)) let filename = paramStr(2) let settingsName = paramStr(3) let ff = newForceField("ffs.toml", settingsName) let boundary = ff.boundary let lennardS = ff.lennardS var particles: seq[Particle] # get particles for i in 0..atomCount: block thisPart: let name = &"c{i}" var attempt = 0 while true: # too many attempts: stop trying to spawn this particle inc attempt if attempt > 10: break thisPart # random position let pos = vector(rand(2 * boundary)-boundary, rand(2*boundary)-boundary, rand(2*boundary) - boundary) # check for overlap, go back to start of while if there is one for p in particles: if (p.pos - pos).len() < lennardS * 2.5: break # this reached? particle successfully spawned particles.add(newParticle(name, pos, 1.0)) break thisPart echo &"{particles.len} particles generated." # and write them to xyz var f = open(filename, fmWrite) appendXyz(f, particles, 0.0) f.close()