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
Ejemplo n.º 2
0
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)
Ejemplo n.º 3
0
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 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