def main(): """ This test shows how to set up Structure container with Particle/Bond-Containers and shows how IDs changed in StructureContainer propagate to values set in BondContainer for its held particle ID values Illustrates how a substructure method can return subgroup """ print "*****************************************************************************************************" print " This test shows how to set up Structure container with Particle/Bond-Containers \n" print " and shows how IDs changed in StructureContainer propagate to values set in BondContainer for its " print " held particle ID values \n" print " Illustrates how a substructure method can return subgroup" print "************************************************************************************ \n" p1 = Particle( [0.2, 1.3, 33.0], "Si", 2.0, 1.23) p2 = Particle( [5.0, 2.3, -22.1], "C", 1.0, 2.34) p3 = Particle( [5.0, 2.3, -20.1], "C", 1.0, 2.34) p4 = Particle( [0.0, 2.3, -20.1], "C", 1.0, 2.34) p5 = Particle( [0.2, 1.3, 33.0], "Si", 2.0, 1.23) b1 = Bond( 5, 2, 1.233, "hooke") # This setup mimics earlier state of test b2 = Bond( 2, 3, 0.500, "hooke") # Still matches with diagram b3 = Bond( 3, 4, 2.301, "hooke") b4 = Bond( 5, 3, 0.828, "hooke") atoms1 = ParticleContainer() atoms1.put(p1) atoms1.put(p2) atoms1.put(p3) atoms1.put(p4) atoms1.put(p5) del atoms1[1] # This is to mimic state of container for an older test bonds = BondContainer() bonds.put(b1) bonds.put(b2) bonds.put(b3) bonds.put(b4) del p1, p2, p3, p4, b1, b2, b3, b4 polymer1 = StructureContainer(atoms1, bonds) del atoms1, bonds print "********************************************************** \n" print polymer1 print diagramAfter print "********************************************************** \n" print "-------------------------------------------------------------------------------- \n" print "********************************************************** \n" print "Testing polymer1.getSubStructure([5,2])" print " currently ID's are reassigned in substructure \n" subpolymer = polymer1.getSubStructure([5,2]) print subpolymer print diagramAfter print "********************************************************** \n" print "********************************************************** \n" print "polymer1 Struture after returning sub-structure" print polymer1 print "********************************************************** \n" print "-------------------------------------------------------------------------------- \n" print "********************************************************** \n" print "Testing polymer1.getSubStructure([2,3,4])" print " currently ID's are reassigned in substructure \n" subpolymer = polymer1.getSubStructure([2,3,4]) print subpolymer print diagramAfter print "********************************************************** \n"
def main(): """ This test shows how to add StructureContainer objects together """ print "************************************************************************************" print " This test shows how to add StructureContainer objects together " print "************************************************************************************ \n" p1 = Particle([0.2, 1.3, 33.0], "Si", 2.0, 1.23) p2 = Particle([5.0, 2.3, -22.1], "C", 1.0, 2.34) p3 = Particle([5.0, 2.3, -20.1], "C", 1.0, 2.34) b1 = Bond(1, 2, 1.233, "hooke") b2 = Bond(2, 3, 0.500, "hooke") atoms1 = ParticleContainer() atoms1.put(p1) atoms1.put(p2) atoms1.put(p3) bonds1 = BondContainer() bonds1.put(b1) bonds1.put(b2) polymer1 = StructureContainer(atoms1, bonds1) # Complete structure 1 p1other = Particle([0.0, 2.3, -20.1], "C", 1.0, 2.34) p2other = Particle([50.0, 0.3, -0.1], "Ar", 2.0, 2.34) b1other = Bond(1, 2, 1.233, "hooke") # Correct ptclIDs for second structure atoms2 = ParticleContainer() atoms2.put(p1other) atoms2.put(p2other) bonds2 = BondContainer() bonds2.put(b1other) polymer2 = StructureContainer(atoms2, bonds2) # Complete structure 2 print "Number of particles in polymer2 = ", polymer2.getPtclNum() del p1, p2, p3, p1other, p2other, b1, b2, b1other, atoms1, atoms2, bonds1, bonds2 print "\n Cleaning memory for initial objects \n" print "-------------------- Before adding --------------------" print "polymer1 = ", polymer1 print "polymer2 = ", polymer2 print " " print "-------------------- After adding --------------------" polymer1 += polymer2 print "polymer1 = ", polymer1 print "Number of particles in polymer1 after add = ", polymer1.getPtclNum() print "-------------------- Results (check above) --------------------" print " 1---b1---2---b2---3 + 1---b1----2 should go to" print " " print " 1---b1---2---b2---3 4---b3----5 \n" print " " print "------ After adding polymer 2 should be unchanged--------------" print "polymer2 = ", polymer2
def main(): """ Illustrates how a substructure method returns subgroup with ONLY particle container included This is for speed considerations """ print "**********************************************************************************************" print "Illustrates how a substructure method returns subgroup with ONLY particle container included" print "This is for speed considerations" print "**********************************************************************************************\n" p1 = Particle([1.1, 1.1, 1.1], "Si", 2.0, 1.23) p2 = Particle([2.2, 2.2, 2.2], "Si", 1.0, 2.34) p3 = Particle([3.3, 3.3, 3.3], "Si", 1.0, 2.34) p4 = Particle([4.4, 4.4, 4.4], "Si", 1.0, 2.34) p5 = Particle([5.5, 5.5, 5.5], "C", 1.0, 2.34) # 1 p6 = Particle([6.6, 6.6, 6.6], "C", 1.0, 2.34) # 2 p7 = Particle([7.7, 7.7, 7.7], "C", 1.0, 2.34) # 3 p8 = Particle([8.8, 8.8, 8.8], "C", 1.0, 2.34) # 4 b1 = Bond(1, 2, 1.11, "hooke") b2 = Bond(2, 3, 2.22, "hooke") b3 = Bond(3, 4, 3.33, "hooke") b4 = Bond(4, 5, 4.44, "hooke") b5 = Bond(5, 6, 5.55, "hooke") b6 = Bond(6, 7, 6.66, "hooke") b7 = Bond(7, 8, 7.77, "hooke") a1 = Angle(1, 2, 3, 1.11, "harmonic") a2 = Angle(2, 3, 4, 2.22, "harmonic") a3 = Angle(3, 4, 5, 3.33, "harmonic") a4 = Angle(4, 5, 6, 4.44, "harmonic") a5 = Angle(5, 6, 7, 5.55, "harmonic") a6 = Angle(6, 7, 8, 6.66, "harmonic") d1 = Dihedral(1, 2, 3, 4, 1.11, "stiff") d2 = Dihedral(2, 3, 4, 5, 2.22, "stiff") d3 = Dihedral(3, 4, 5, 6, 3.33, "stiff") d4 = Dihedral(4, 5, 6, 7, 4.44, "stiff") d5 = Dihedral(5, 6, 7, 8, 5.55, "stiff") atoms1 = ParticleContainer() atoms1.put(p1) atoms1.put(p2) atoms1.put(p3) atoms1.put(p4) atoms1.put(p5) atoms1.put(p6) atoms1.put(p7) atoms1.put(p8) bonds = BondContainer() bonds.put(b1) bonds.put(b2) bonds.put(b3) bonds.put(b4) bonds.put(b5) bonds.put(b6) bonds.put(b7) angles = AngleContainer() angles.put(a1) angles.put(a2) angles.put(a3) angles.put(a4) angles.put(a5) angles.put(a6) dihedrals = DihedralContainer() dihedrals.put(d1) dihedrals.put(d2) dihedrals.put(d3) dihedrals.put(d4) dihedrals.put(d5) del p1, p2, p3, p4, p5, p6, p7, p8 del b1, b2, b3, b4, b5, b6, b7 del a1, a2, a3, a4, a5, a6 del d1, d2, d3, d4, d5 polymer1 = StructureContainer(atoms1, bonds, angles, dihedrals) del atoms1, bonds, angles, dihedrals print "********************************************************** \n" print "polymer1 Structure before returning sub-structure" print polymer1 print "********************************************************** \n" print "-------------------------------------------------------------------------------- \n" print "********************************************************** \n" print "Testing polymer1.getSubParticleContainer([2,3,4])" print " currently ID's are reassigned in substructure \n" subPtclC = polymer1.getSubStructure([2, 3, 4], particlesOnly=True) print subPtclC print "********************************************************** \n"
def main(): """ Tests a specifc workflow for LAMMPS that uses the simulationLAMMPS1 derived class """ global g global p # Get useful methods g=Geometry() # Get comm object p = mpiBase.getMPISerialObject() rank = p.getRank() size = p.getCommSize() # Sync random stream for tests random.seed(0) ############################################################################################# # # Generate list of [gid, x,y,z] points ---> allPoints list # copied on all processors. # Global pt index included # UNITS distance --> A [0.1 nm] # ############################################################################################# rad_avg = 15.0 # Moving to use this to make rad_sig = 0.025 # initial cubic grid thats used to pass to MD ptcl_dist = 10.0 # # NOTE: this is an arbitrary choice cutoff_dist = math.sqrt(2)*((2.00 * rad_avg) + ptcl_dist) nQD_spacing = (2.00 * rad_avg) + ptcl_dist # Makes number of points along side grid nQDs = [5, 5, 5] sysLs = setSystemSizes(nQDs, nQD_spacing) # Set boundary condition list (used in PBC calc) xL = sysLs[0] yL = sysLs[1] zL = sysLs[2] bcLs = [0.0, yL[1]-yL[0], zL[1]-zL[0] ] # x is NOT PB # Status info if rank == 0: print "rad_avg = ", rad_avg print "rad_sig = ", rad_sig print "cutoff_dist = ", cutoff_dist print " " print "bcLs = ", bcLs print "sysLs = ", sysLs print " " ############################################################################################# # Generate initial points p.barrier() tmpPoints = setRandomGridPoints(nQDs, rad_avg, ptcl_dist) # Generate global pts lst allPoints = p.bcast(tmpPoints) # ensures rand pts same across procs numpoints = len(allPoints) # Total number of points (for diag) if numpoints == 0: print "Number of points generated == 0" sys.exit(3) myPoints = p.splitListOnProcs(allPoints) # Split elements on across processors p.barrier() ############################################################################################# ################################################################### # Store particles in struc and find neighbors/bonds # ptPos includes index eg. [1, 3.4, 1.2, -2.0] nanoPtcls = ParticleContainer() nanoBonds = BondContainer() for ptPos in allPoints: axisLoc = [bcLs[1]/2.0, bcLs[2]/2.0] cylinderRadius = 120.0 inside = isPtInCylinder(ptPos[1:], axisLoc, "yz", cylinderRadius) if inside: pt = Particle(ptPos[1:], type="QDbig", mass=2.0) tagsD = {"molnum":1, "QDSizeAvg":20.0} else: pt = Particle(ptPos[1:], type="QDsmall", mass=1.0) tagsD = {"molnum":1, "QDSizeAvg":15.0} pt.setTagsDict(tagsD) nanoPtcls.put(pt) p.barrier() # Get bond info allDist, allNeighbors, numTotalNeighbors, allBonds = \ setQDNeighbors(myPoints, allPoints, cutoff_dist, bcLs, rank, size) if rank == 0: print "Begin building bond container" # Put bonds into container for bond in allBonds: if not nanoBonds.hasBond(bond): # Check if bond is unique bnd = Bond(bond[0], bond[1], type="normBond") # Put into STREAMM object nanoBonds.put(bnd) # add if not in container p.barrier() if rank == 0: print "length of bond container = ", len(nanoBonds) ############################################################################### ############################################################################ # Write LAMMPS file with atoms/bonds strucQD = StructureContainer(nanoPtcls, nanoBonds) simObjQD = SimulationLAMMPS1("LammpsAug14", verbose=False) simObjQD.setStructureContainer(strucQD) if isinstance(simObjQD, SimulationLAMMPS1): print "strucQD is a SimulationLAMMPS1" else: print "strucQD is NOT a SimulationLAMMPS1" boxSizes = sysLs strucQD.setBoxLengths(boxSizes) small_rad_avg = 15.0 big_bond_min = (2.0* rad_avg) + ptcl_dist small_sigma_min = ((2.0*small_rad_avg) + ptcl_dist) / pow(2, 1/6.) big_sigma_min = ((2.0* rad_avg) + ptcl_dist) / pow(2, 1/6.) ptclParamMap = {("QDsmall", "epsilon"):1.0, ("QDsmall", "sigma"):small_sigma_min, ("QDbig", "epsilon"):1.0, ("QDbig", "sigma"):big_sigma_min} # Just one bond type for now bondParamMap = {("normBond", "Kenergy"):1.0, ("normBond", "r0"):big_bond_min} if rank == 0: # nanoPtcls.scatterPlot() # strucQD.dumpLammpsInputFile("qd.data", ptclParamMap, bondParamMap) # strucQD.writeInput("qd.data", ptclParamMap, bondParamMap) # simObjQD.writeInput("qd.data", ptclParamMap, bondParamMap) simObjQD.setCoeffs(ptclParamMap, bondParamMap) simObjQD.writeInput("qd.data") # For format of test check os.system("cat qd.data")
def main(): """ This test shows structureContainer functionality with angles included """ print "************************************************************************************" print " This test shows structureContainer functionality with angles included" print "************************************************************************************ \n" p1 = Particle( [1.1, 1.1, 1.1], "Si", 2.0, 1.23) p2 = Particle( [2.2, 2.2, 2.2], "Si", 1.0, 2.34) p3 = Particle( [3.3, 3.3, 3.3], "Si", 1.0, 2.34) # p4 = Particle( [4.4, 4.4, 4.4], "C", 1.0, 2.34) # 1 p5 = Particle( [5.5, 5.5, 5.5], "C", 1.0, 2.34) # 2 p6 = Particle( [6.6, 6.6, 6.6], "C", 1.0, 2.34) # 3 b1 = Bond( 1, 2, 1.11, "hooke") b2 = Bond( 2, 3, 2.22, "hooke") # b3 = Bond( 1, 2, 3.33, "hooke") b4 = Bond( 2, 3, 4.44, "hooke") a1 = Angle(1, 2, 3, 1.11, "harmonic") # a2 = Angle(1, 2, 3, 2.22, "harmonic") atoms1 = ParticleContainer() atoms2 = ParticleContainer() atoms1.put(p1) atoms1.put(p2) atoms1.put(p3) # atoms2.put(p4) atoms2.put(p5) atoms2.put(p6) bonds1 = BondContainer() bonds2 = BondContainer() bonds1.put(b1) bonds1.put(b2) bonds2.put(b3) bonds2.put(b4) angles1 = AngleContainer() angles2 = AngleContainer() angles1.put(a1) angles2.put(a2) polymer1 = StructureContainer(atoms1, bonds1, angles1) polymer2 = StructureContainer(atoms2, bonds2, angles2) del p1, p2, p3, p4, p5, p6, b1, b2, b3, b4, a1, a2 del atoms1, atoms2, bonds1, bonds2, angles1, angles2 print "\n Cleaning memory for initial objects \n" print "-------------------- Initial structures --------------------" print "polymer1 = ", polymer1 print "polymer2 = ", polymer2 print " " print "-------------- After adding (polymer1 += polymer2) ----------------" polymer2 += polymer1 print "polymer2 = ", polymer2
def main(): """ This test shows compressing IDs when structureContainer has angles included """ p1 = Particle([1.1, 1.1, 1.1], "Si", 2.0, 1.23) p2 = Particle([2.2, 2.2, 2.2], "Si", 1.0, 2.34) p3 = Particle([3.3, 3.3, 3.3], "Si", 1.0, 2.34) p4 = Particle([0.0, 0.0, 0.0], "Si", 1.0, 2.34) # p5 = Particle([4.4, 4.4, 4.4], "C", 1.0, 2.34) # 1 p6 = Particle([5.5, 5.5, 5.5], "C", 1.0, 2.34) # 2 p7 = Particle([6.6, 6.6, 6.6], "C", 1.0, 2.34) # 3 b1 = Bond(1, 3, 1.11, "hooke") b2 = Bond(3, 4, 2.22, "hooke") # b3 = Bond(1, 2, 3.33, "hooke") b4 = Bond(2, 3, 4.44, "hooke") a1 = Angle(1, 3, 4, 1.11, "harmonic") # a2 = Angle(1, 2, 3, 2.22, "harmonic") atoms1 = ParticleContainer() atoms2 = ParticleContainer() atoms1.put(p1) atoms1.put(p2) atoms1.put(p3) atoms1.put(p4) # atoms2.put(p5) atoms2.put(p6) atoms2.put(p7) del atoms1[2] # remove 2nd particle so ID's are non-consecutive bonds1 = BondContainer() bonds2 = BondContainer() bonds1.put(b1) bonds1.put(b2) bonds2.put(b3) bonds2.put(b4) angles1 = AngleContainer() angles2 = AngleContainer() angles1.put(a1) angles2.put(a2) polymer1 = StructureContainer(atoms1, bonds1, angles1) polymer2 = StructureContainer(atoms2, bonds2, angles2) del p1, p2, p3, p4, p5, p6, b1, b2, b3, b4, a1, a2 del atoms1, atoms2, bonds1, bonds2, angles1, angles2 print "\n Cleaning memory for initial objects \n" print "-------------------- Initial structures --------------------" print "polymer1 = ", polymer1 print "polymer2 = ", polymer2 print " " print "-------------- After adding (polymer2 += polymer1) ----------------" polymer2 += polymer1 print "polymer2 = ", polymer2 polymer2.compressPtclIDs() print "-------------------- After compressing --------------------" print "polymer2 = ", polymer2
def main(): """ This test shows structureContainer functionality with dihedrals included """ print "************************************************************************************" print " This test shows structureContainer functionality with dihedrals included" print "************************************************************************************ \n" p1 = Particle([1.1, 1.1, 1.1], "Si", 2.0, 1.23) p2 = Particle([2.2, 2.2, 2.2], "Si", 1.0, 2.34) p3 = Particle([3.3, 3.3, 3.3], "Si", 1.0, 2.34) p4 = Particle([4.4, 4.4, 4.4], "Si", 1.0, 2.34) # p5 = Particle([5.5, 5.5, 5.5], "C", 1.0, 2.34) # 1 p6 = Particle([6.6, 6.6, 6.6], "C", 1.0, 2.34) # 2 p7 = Particle([7.7, 7.7, 7.7], "C", 1.0, 2.34) # 3 p8 = Particle([8.8, 8.8, 8.8], "C", 1.0, 2.34) # 4 b1 = Bond(1, 2, 1.11, "hooke") b2 = Bond(2, 3, 2.22, "hooke") b3 = Bond(3, 4, 3.33, "hooke") # b4 = Bond(1, 2, 4.44, "hooke") b5 = Bond(2, 3, 5.55, "hooke") b6 = Bond(3, 4, 6.66, "hooke") a1 = Angle(1, 2, 3, 1.11, "harmonic") # a2 = Angle(1, 2, 3, 2.22, "harmonic") d1 = Dihedral(1, 2, 3, 4, 1.11, "stiff") # d2 = Dihedral(1, 2, 3, 4, 2.22, "stiff") atoms1 = ParticleContainer() atoms2 = ParticleContainer() atoms1.put(p1) atoms1.put(p2) atoms1.put(p3) atoms1.put(p4) # atoms2.put(p5) atoms2.put(p6) atoms2.put(p7) atoms2.put(p8) bonds1 = BondContainer() bonds2 = BondContainer() bonds1.put(b1) bonds1.put(b2) bonds1.put(b3) # bonds2.put(b4) bonds2.put(b5) bonds2.put(b6) angles1 = AngleContainer() angles2 = AngleContainer() angles1.put(a1) angles2.put(a2) dih1 = DihedralContainer() dih2 = DihedralContainer() dih1.put(d1) dih2.put(d2) polymer1 = StructureContainer(atoms1, bonds1, angles1, dih1) polymer2 = StructureContainer(atoms2, bonds2, angles2, dih2) del p1, p2, p3, p4, p5, p6, p7, p8 del b1, b2, b3, b4, b5, b6, a1, a2, d1, d2 del atoms1, atoms2, bonds1, bonds2, angles1, angles2, dih1, dih2 print "\n Cleaning memory for initial objects \n" print "-------------------- Initial structures --------------------" print "polymer1 = ", polymer1 print "polymer2 = ", polymer2 print " " print "-------------- After adding (polymer1 += polymer2) ----------------" polymer2 += polymer1 print "polymer2 = ", polymer2
def main(): """ This shows operations on empty StructureContainer objects for 'robustness' """ print "************************************************************************************" print " This shows operations on empty StructureContainer objects for 'robustness'" print "************************************************************************************ \n" atoms1 = ParticleContainer() bonds1 = BondContainer() p1 = Particle([0.2, 1.3, 33.0], "Si", 2.0, 1.23) p2 = Particle([5.0, 2.3, -22.1], "C", 1.0, 2.34) p3 = Particle([5.0, 2.3, -20.1], "C", 1.0, 2.34) b1 = Bond(1, 2, 1.233, "hooke") b2 = Bond(2, 3, 0.500, "hooke") atoms1.put(p1) atoms1.put(p2) atoms1.put(p3) bonds1.put(b1) bonds1.put(b2) atoms2 = ParticleContainer() bonds2 = BondContainer() polymer1 = StructureContainer(atoms1, bonds1) # Non-empty structure 1 polymer2 = StructureContainer(atoms2, bonds2) # Empty structure 2 # ------------------------------------------------------------------------------------------------------------------------ print "Non-empty container", polymer1 print "Empty container", polymer2 print "Testing empty dump" polymer2.dump("empty") print "Testing empty compressPtclIDs" polymer2.compressPtclIDs() print "Testing empty getSubStructure" subStruc = polymer2.getSubStructure([]) print "subStruc = ", subStruc print "Testing empty getPtclPositions" posList = polymer2.getPtclPositions() print "posList = ", posList print "------------------------------------------------------------------------------------ \n" print "Testing struc add --> non-empty (polymer1) += empty (polymer2)" polymer1 += polymer2 print "polymer1 = ", polymer1 print "------------------------------------------------------------------------------------ \n" print "polymer2 = ", polymer2 print "------------------------------------------------------------------------------------ \n" print "Testing struc add --> empty (polymer2) += non-empty (polymer1)" polymer2 += polymer1 print "polymer2 = ", polymer2 print "------------------------------------------------------------------------------------ \n" print "polymer1 = ", polymer1 print "------------------------------------------------------------------------------------ \n" print "Testing empty getSubStructure with non-zero id list (should return ERROR)" polymer3 = StructureContainer() subStruc = polymer3.getSubStructure([1, 2]) print "subStruc = ", subStruc