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 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
示例#3
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)
示例#4
0
def main():
    """
    Read in gaussian fchk file and create an xyz file 
    """

    #
    # Read options
    #
    options, args = get_options()
    #
    #  Initialize blank system
    #
    struc_o = StructureContainer()
    #struc_o.unset_verbose()
    param_o = ParameterContainer()

    struc_o, param_o = read_lmpdata(struc_o, param_o, options.in_data)
    print struc_o
    print param_o
    add_residue_prop(struc_o)
    add_gtype_prop(struc_o)

    print " Writing xyz file {}.xyz".format(options.out_id)
    comment = " From data file {} ".format(options.in_data)
    append = False
    struc_o.ptclC.write_xmol("{}.xyz".format(options.out_id), comment, append)
    print " Writing gromacs files {} ".format(options.out_id)
    write_gro(struc_o, "{}.gro".format(options.out_id))
    write_top(struc_o, "{}.top".format(options.out_id),
              "{}.itp".format(options.out_id))
    write_itp(param_o, "{}.itp".format(options.out_id))
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"
示例#6
0
def main():
    """
    Read in gaussian fchk file and create an xyz file 
    """

    #
    # Read options
    #
    options, args = get_options()
    #
    #  Initialize blank system
    #
    struc_o = StructureContainer()
    #struc_o.unset_verbose()
    param_o = ParameterContainer()

    struc_o.read_cply(options.in_cply)

    search_i = dict()
    search_i = create_search(search_i, options.symbol, options.label,
                             options.fftype, options.residue, options.resname,
                             options.chain, options.ring)

    if (len(search_i) > 0):

        if (options.verbose):
            log_line = "\n Searching group i {} {} ".format(
                search_i, len(search_i))
            #log_out.write(log_line)
            if (options.verbose): print log_line
        list_i = struc_o.ptclC.getParticlesWithTags(search_i)
        struc_i = struc_o.getSubStructure(list_i, particlesOnly=True)
    else:
        struc_i = struc_o

    print struc_i

    if (len(options.xyz) > 0):
        log_line = " Setting types to {} ".format(options.xyz)
        if (options.verbose):
            print log_line
        struc_i.set_type(options.xyz)

    comment = " From data file {} ".format(options.in_cply)
    append = False
    struc_i.ptclC.write_xmol("{}".format(options.out_xyz), comment, append)
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()
示例#8
0
def main():
    """
    Read in gaussian fchk file and create an xyz file 
    """

    #        
    # Read options 
    #
    options, args = get_options()
    #
    #  Initialize blank system 
    # 
    struc_o = StructureContainer()
    #struc_o.unset_verbose()
    param_o = ParameterContainer()

    struc_o.read_cply(options.in_cply)

    search_i = dict()
    search_i = create_search(search_i,options.symbol,options.label,options.fftype,options.residue,options.resname,options.chain,options.ring)

    if( len(search_i) > 0 ):


        if( options.verbose ):
            log_line = "\n Searching group i {} {} ".format(search_i,len(search_i))
            #log_out.write(log_line)
            if( options.verbose ): print log_line
        list_i = struc_o.ptclC.getParticlesWithTags(search_i)
        struc_i = struc_o.getSubStructure(list_i, particlesOnly=True )
    else:
        struc_i = struc_o
        
    print struc_i

    if( len( options.xyz) > 0 ):
        log_line = " Setting types to {} ".format(options.xyz)
        if( options.verbose ):
            print log_line
        struc_i.set_type(options.xyz)
        
    comment = " From data file {} ".format( options.in_cply)
    append = False 
    struc_i.ptclC.write_xmol("{}".format(options.out_xyz),comment,append)
示例#9
0
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 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
示例#11
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
示例#12
0
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 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():
    """
    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 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
示例#17
0
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