def main(): """ This test illustrates the setting a ParticleContainer with pre-existing IDs """ print "************************************************************************************" print " This test illustrates the setting a ParticleContainer with pre-existing IDs " 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([90.0, -0.0, -80.1], "Zr", 1.0, 4.0) idList = [2, 3, 6, 10] print "Using idList = ", idList, " to initialize particle container" atoms1 = ParticleContainer(idList) print "Initial atoms1 state from a pre-set ID list ", atoms1, "\n" atoms1[2] = p1 atoms1[3] = p2 atoms1[6] = p3 atoms1[10] = p4 print "atoms1 state from a pre-set ID list populated atoms1[..] = ... ", atoms1, "\n" atoms1.put(p5) print "atoms1 state after a put(p5) call ", atoms1, "\n"
def main(): """ This test shows how to add StructureContainer objects together A special test to double-check re-labeling ... add a big container to a 'small' one """ print "***************************************************************************************" print " This test shows how to add StructureContainer objects together " print " A special test to double-check re-labeling ... add a big container to a 'small' one " print "*************************************************************************************** \n" p1 = Particle([1.1, 1.1, 1.1], "Si", 2.0, 1.23) p2 = Particle([2.2, 2.2, 2.2], "C", 1.0, 2.34) p3 = Particle([3.3, 3.3, 3.3], "C", 1.0, 2.34) b1 = Bond(1, 2, 1.111, "hooke") b2 = Bond(2, 3, 2.222, "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 completely p1other = Particle([1.11, 1.11, 1.11], "C", 1.0, 2.34) p2other = Particle([2.22, 2.22, 2.22], "Ar", 2.0, 2.34) b1other = Bond(1, 2, 1.1, "hooke-2") # Correct ptclIDs for second structure atoms2 = ParticleContainer() atoms2.put(p1other) atoms2.put(p2other) bonds2 = BondContainer() bonds2.put(b1other) polymer2 = StructureContainer(atoms2, bonds2) # Complete structure 1 completely 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 polymer2 += polymer1 print "polymer2 = ", polymer2
def main(): """ This test shows various operators within Particle and ParticleContainer classes. Shows memory management structure and access methods. """ 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) atoms1 = ParticleContainer() atoms2 = ParticleContainer() atoms1.put(p1) atoms1.put(p2) # atoms2.put(p3) atoms2.put(p4) del p1, p2, p3, p4 print "\n Cleaning memory for initial objects \n" print "x = atoms1[1] returns x as an effective 'reference' \n" x = atoms1[1] print "x = ", x.__dict__, "\n" x.position = [1.0, 1.0, 1.0] print "after changing with x.position = [1.0, 1.0, 1.0]" print "x = ", x.__dict__, "\n" # This value has been changed by code above print "atoms1 has been changed" print atoms1 print "before, atoms1--> ", atoms1, "\n" del atoms1[2] print "after 'del atoms1[2]' atoms1 --> ", atoms1, "\n" print "Testing 'in' operator (1 in atoms1)" if (1 in atoms1): print "atoms1 contains gid 1" else: print "key not found in atoms1" print "Testing 'in' operator (5 in atoms1)" if (5 in atoms1): print "atoms1 contains gid 5" else: print "key not found in atoms1" print " " atoms1 += atoms2 print "Will print the new atoms1 after adding atoms1 += atoms2" print atoms1
def runStrucAdd(numPtcls1, numPtcls2): """ Creates structures with ptcls and bonds between consecutive IDs Adds and reports timing Args: numPtcls1 (int): # of ptcls in first struc numPtcls2 (int): # of ptcls in second struc Returns: (initTime, addTime, compressTime) """ atoms1 = ParticleContainer() bonds1 = BondContainer() atoms2 = ParticleContainer() bonds2 = BondContainer() start_time = time.time() for n in range(numPtcls1): pobj1 = Particle([1.1, 1.1, 1.1], "Si", 2.0, float(n + 1)) atoms1.put(pobj1) for n in range(1, numPtcls1): bobj1 = Bond(n, n + 1, 1.233, "hooke-1") bonds1.put(bobj1) for n in range(numPtcls2): pobj2 = Particle([2.2, 2.2, 2.2], "C", 1.0, float(n + 1)) atoms2.put(pobj2) for n in range(1, numPtcls2): bobj2 = Bond(n, n + 1, 1.233, "hooke-2") bonds2.put(bobj2) end_time = time.time() initTime = end_time - start_time polymer1 = StructureContainer(atoms1, bonds1) # Complete structure 1 polymer2 = StructureContainer(atoms2, bonds2) # Complete structure 2 del atoms1, atoms2 print "\n Cleaning memory for initial objects \n" start_time = time.time() polymer1 += polymer2 end_time = time.time() addTime = end_time - start_time start_time = time.time() polymer1.compressPtclIDs() end_time = time.time() compressTime = end_time - start_time return (numPtcls1, numPtcls2, initTime, addTime, compressTime)
def main(): """ This test illustrates the different ways ParticleContainer can set Particle object data (eg the [] operator on ParticleContainer) """ 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([9.0, -8.0, -80.1], "Ar", 1.0, 4.0) p6 = Particle([90.0, -0.0, -80.1], "Zr", 1.0, 4.0) atoms1 = ParticleContainer() atoms1.put(p1) atoms1.put(p2) atoms1.put(p3) atoms1.put(p4) print "Initial atoms1 state from an empty container, populated with put()", atoms1, "\n" tag = 4 print "Replacing ID tag", tag, "with p5 particle data \n" atoms1[4] = p5 print "atoms1 state", atoms1, "\n" tag = 5 print "Setting ID tag that does not exist", tag, "with p6 particle data ---> atoms1[5]=p6 \n" atoms1[5] = p6 print "atoms1 state", atoms1, "\n"
def main(): """ This test shows how the setPtclPos method works to externally set all particle positions from a list """ print "************************************************************************************" print " This test shows how the setPtclPos method works to externally set all particle " print " positions from a list" 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) b1 = Bond(1, 2, 1.233, "hooke") b2 = Bond(2, 3, 0.500, "hooke") b3 = Bond(3, 4, 2.301, "hooke") b4 = Bond(1, 3, 0.828, "hooke") atoms1 = ParticleContainer() atoms1.put(p1) atoms1.put(p2) atoms1.put(p3) atoms1.put(p4) 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 polymer1.setBoxLengths([[-3.0, 100], [-5, 23.0], [34.3, 100.1]]) print "Initial state of structure before reset ", polymer1 newPtclPos = [[1, 0.111, 0.222, 0.333], [2, 0.222, 0.333, 0.444], [4, 0.444, 0.555, 0.666]] print "new positions = ", newPtclPos polymer1.setPtclPositions(newPtclPos) ptclPosList = polymer1.getPtclPositions() print "new positions from structure = ", ptclPosList print " " print "After position reset/get ", polymer1
def main(): """ This test shows how to save/dump/restore state of structureContainers using pickle """ print "************************************************************************************" print " This test shows how to save/dump/restore state of structureContainers using pickle" 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) b1 = Bond(1, 2, 1.233, "hooke") b2 = Bond(2, 3, 0.500, "hooke") b3 = Bond(3, 4, 2.301, "hooke") b4 = Bond(1, 3, 0.828, "hooke") atoms1 = ParticleContainer() atoms1.put(p1) atoms1.put(p2) atoms1.put(p3) atoms1.put(p4) 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 polymer1.setBoxLengths([[-3.0, 100], [-5, 23.0], [34.3, 100.1]]) print "Initial state of structure before dump ", polymer1 print "-------------------------------------------------------------------------------- \n" polymer1.dump('polymer1') polymerNew = StructureContainer() polymerNew.restore('polymer1.pkl') print "After load from pickle \n" print polymerNew print "-------------------------------------------------------------------------------- \n"
def main(): """ This test shows basics of the Simulation classes Highlights differences between setting reference to the structure container and a deepcopy """ print "************************************************************************************" print " This test shows basics of the Simulation classes" print " Highlights differences between setting reference to the structure" print " container and a deepcopy" 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) atoms1 = ParticleContainer() atoms1.put(p1) atoms1.put(p2) atoms1.put(p3) polymer1 = StructureContainer( atoms1, verbose=False) # Complete structure 1 completely polymer2 = StructureContainer(verbose=False) polymer2 += polymer1 del p1, p2, p3, atoms1 print "\n Cleaning memory for initial objects \n" print "-------------------- Before adding --------------------" print "polymer1 = ", polymer1 print "polymer2 = ", polymer2 print " " simObj1 = Simulation("GaussianJuly2014") simObj2 = Simulation("Lammps012038") simObj1.setStructureContainer(polymer1) simObj2.copyStructureContainerInto(polymer1) del polymer1.ptclC[1] print "-------------------- After changing polymer1 struc --------------------" print "polymer1 = ", polymer1 simObj1.printStruc() simObj2.printStruc()
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
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 various operators within Dihedral and DihedralContainer classes Also shows memory management structure and access methods """ print "************************************************************************************" print " This test shows various operators within Dihedral and DihedralContainer classes " print " Also shows memory management structure and access methods " 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) p6 = Particle([6.6, 6.6, 6.6], "C", 1.0, 2.34) p7 = Particle([7.7, 7.7, 7.7], "C", 1.0, 2.34) p8 = Particle([8.8, 8.8, 8.8], "C", 1.0, 2.34) b1 = Bond(1, 2, 1.11, "hooke") b2 = Bond(2, 3, 2.22, "hooke") # b3 = Bond(1, 2, 3.33, "hooke") b4 = Bond(1, 2, 4.44, "hooke") 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) # 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) dihedrals1 = DihedralContainer() dihedrals2 = DihedralContainer() dihedrals1.put(d1) dihedrals2.put(d2) del p1, p2, p3, p4, p5, p6, b1, b2, b3, b4, d1, d2 print "\n Cleaning memory for initial objects \n" print "dihedral1 container" print dihedrals1 print " " print "dihedral2 container" print dihedrals2 print "Testing 'in' operator (1 in dihedrals1)" if (1 in dihedrals1): print "dihedrals1 contains gid 1" else: print "key not found in dihedrals1" print "Testing 'in' operator (5 in dihedrals1)" if (5 in dihedrals1): print "dihedrals1 contains gid 5" else: print "key not found in dihedrals1" print " " dihedrals1 += dihedrals2 print "Will print the new dihedrals1 after adding dihedrals1 += dihedrals2" print dihedrals1 print "Check for pre-existing dihedral" if dihedrals1.hasDihedral([4, 3, 2, 1]): print "dihedral 1--2--3--4 exists" else: print "dihedral 1--2--3--4 does NOT exists" print "Check for pre-existing dihedral" if dihedrals1.hasDihedral([2, 3, 1, 4]): print "dihedral 2--3--1--4 exists" else: print "dihedral 2--3--1--4 does NOT exists"
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(): """ This test shows how reorder (compress) global IDs for a StructureContainer """ 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) p3other = Particle([50.0, 0.3, -0.1], "Ar", 2.0, 2.34) b1other = Bond(1, 3, 1.233, "hooke") # Correct ptclIDs for second structure atoms2 = ParticleContainer() atoms2.put(p1other) atoms2.put(p2other) atoms2.put(p3other) del atoms2[2] # remove 2nd particle so ID's are non-consecutive bonds2 = BondContainer() bonds2.put(b1other) polymer2 = StructureContainer(atoms2, bonds2) # Complete structure 1 completely 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 --------------------" polymer2 += polymer1 print "polymer2 = ", polymer2 polymer2.compressPtclIDs() print "-------------------- After compressing --------------------" print "polymer2 = ", polymer2
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 illustrates the search capability for multiple tags This can be combined new class method that returns iterator over search results """ print "************************************************************************************" print " This test illustrates the search capability for multiple tags " print " This can be combined new class method that returns iterator over search results " print "************************************************************************************ \n" p1 = Particle([0.2, 1.3, 33.0], "Si", 2.0, 1.23) tagsD = {"molnum": 1, "ringnum": 4} p1.setTagsDict(tagsD) p2 = Particle([5.0, 2.3, -22.1], "C", 1.0, 2.34) tagsD = {"molnum": 2, "ringnum": 4} p2.setTagsDict(tagsD) p3 = Particle([5.0, 2.3, -20.1], "C", 1.0, 2.34) tagsD = {"molnum": 1, "ringnum": 4} p3.setTagsDict(tagsD) p4 = Particle([0.0, 2.3, -20.1], "Si", 1.0, 2.34) tagsD = {"molnum": 2, "ringnum": 4} p4.setTagsDict(tagsD) p5 = Particle([1.0, 2.3, -20.1], "C", 1.0, 5.34) tagsD = {"molnum": 2, "ringnum": 2} p5.setTagsDict(tagsD) p6 = Particle([8.0, 2.3, -20.1], "Si", 1.0, 8.00) tagsD = {"molnum": 2, "ringnum": 3} p6.setTagsDict(tagsD) p7 = Particle([8.0, 2.3, -20.1], "O", 1.0, 8.00) tagsD = {"molnum": 2, "ringnum": 3} p7.setTagsDict(tagsD) p8 = Particle([8.0, 2.3, -20.1], "O", 1.0, 8.00) tagsD = {"molnum": 2, "ringnum": 3} p8.setTagsDict(tagsD) p9 = Particle([8.0, 2.3, -20.1], "H", 1.0, 8.00) tagsD = {"molnum": 2, "ringnum": 3} p9.setTagsDict(tagsD) 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) atoms1.put(p9) del p1, p2, p3, p4, p5, p6, p7, p8, p9 print "atoms1 initially contains all of the following" print atoms1 print " " # ----------------------------------------------------------- print "This call should exit with error message" typeMass = atoms1.getTypeInfoDict()
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 various operators within Angle and AngleContainer classes. Shows memory management structure and access methods """ 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) # ptcl 1 p5 = Particle([5.5, 5.5, 5.5], "C", 1.0, 2.34) # ptcl 2 p6 = Particle([6.6, 6.6, 6.6], "C", 1.0, 2.34) # ptcl 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) del p1, p2, p3, p4, p5, p6, b1, b2, b3, b4, a1, a2 print "\n Cleaning memory for initial objects \n" print "angles1 container" print angles1 print " " print "angles2 container" print angles2 print "Testing 'in' operator (1 in angles1)" if (1 in angles1): print "angles1 contains gid 1" else: print "key not found in angles1" print "Testing 'in' operator (5 in angles1)" if (5 in angles1): print "angles1 contains gid 5" else: print "key not found in angles1" print " " angles1 += angles2 print "Will print the new angles1 after adding angles1 += angles2" print angles1 print "Check for pre-existing angle" if angles1.hasAngle([3, 2, 1]): print "angle 1--2--3 exists" else: print "angle 1--2--3 does NOT exists" print "Check for pre-existing angle" if angles1.hasAngle([2, 3, 1]): print "angle 2--3--1 exists" else: print "angle 2--3--1 does NOT exists"
def main(): """ This test illustrates the search capability for multiple tags This can be combined new class method that returns iterator over search results """ print "************************************************************************************" print " This test illustrates the search capability for multiple tags " print " This can be combined new class method that returns iterator over search results " print "************************************************************************************ \n" p1 = Particle( [0.2, 1.3, 33.0], "Si", 2.0, 1.23) tagsD = {"molnum":1,"ringnum":4} p1.setTagsDict(tagsD) p2 = Particle( [5.0, 2.3, -22.1], "C", 1.0, 2.34) tagsD = {"molnum":2,"ringnum":4} p2.setTagsDict(tagsD) p3 = Particle( [5.0, 2.3, -20.1], "C", 1.0, 2.34) tagsD = {"molnum":1, "ringnum":4} p3.setTagsDict(tagsD) p4 = Particle( [0.0, 2.3, -20.1], "Si", 1.0, 2.34) tagsD = {"molnum":2,"ringnum":4} p4.setTagsDict(tagsD) p5 = Particle( [1.0, 2.3, -20.1], "C", 1.0, 5.34) tagsD = {"molnum":2,"ringnum":2} p5.setTagsDict(tagsD) p6 = Particle( [8.0, 2.3, -20.1], "Si", 1.0, 8.00) tagsD = {"molnum":2,"ringnum":3} p6.setTagsDict(tagsD) p7 = Particle( [8.0, 2.3, -20.1], "O", 1.0, 8.00) tagsD = {"molnum":2,"ringnum":3} p7.setTagsDict(tagsD) p8 = Particle( [8.0, 2.3, -20.1], "O", 1.0, 8.00) tagsD = {"molnum":2,"ringnum":3} p8.setTagsDict(tagsD) p9 = Particle( [8.0, 2.3, -20.1], "H", 1.0, 8.00) tagsD = {"molnum":2,"ringnum":3} p9.setTagsDict(tagsD) """ print "p1 --> ", p1.__dict__ print "p1 has molnum=1 ", p1.isTagEqualTo("molnum", 1) print "p1 has molnum=100 ", p1.isTagEqualTo("molnum", 100) print "p3 has molnum=2 ", p3.isTagEqualTo("molnum", 2) """ 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) atoms1.put(p9) del p1, p2, p3, p4, p5, p6, p7, p8, p9 print "atoms1 initially contains all of the following" print atoms1 # This should fail # print "Testing callable method ", atoms1() print " " # ----------------------------------------------------------- searchD = {'molnum':2, 'type':"Si"} print "Print only atoms1 with search....", searchD, "\n" subList = atoms1.getParticlesWithTags(searchD) for id, ptcl in atoms1(subList): print "id = ", id, " ptclObj = ",str(ptcl)," molnum ", ptcl.tagsDict["molnum"],"ringnum", ptcl.tagsDict["ringnum"] print "--------------------------------------------------------------------------------- \n" searchD = {'molnum':2, 'type':"Si",'ringnum':4} print "Print only atoms1 with search....", searchD, "\n" subList = atoms1.getParticlesWithTags(searchD) for id, ptcl in atoms1(subList): print "id = ", id, " ptclObj = ",str(ptcl)," molnum ", ptcl.tagsDict["molnum"],"ringnum", ptcl.tagsDict["ringnum"] print "--------------------------------------------------------------------------------- \n" searchD = {'type':"Si", 'ringnum':[3, 4]} print "Print only atoms1 with search....", searchD, "\n" subList = atoms1.getParticlesWithTags(searchD) for id, ptcl in atoms1(subList): print "id = ", id, " ptclObj = ",str(ptcl)," molnum ", ptcl.tagsDict["molnum"],"ringnum", ptcl.tagsDict["ringnum"] print "--------------------------------------------------------------------------------- \n" searchD = {'type':["Si","O"], 'ringnum':[2, 3, 4]} print "Print only atoms1 with search....", searchD, "\n" subList = atoms1.getParticlesWithTags(searchD) for id, ptcl in atoms1(subList): print "id = ", id, " ptclObj = ",str(ptcl)," molnum ", ptcl.tagsDict["molnum"],"ringnum", ptcl.tagsDict["ringnum"] 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