Esempio n. 1
0
def uc_test3():
    uc = UnitCell()

    at1 = Atom(symbol='Fe', mass=57)
    at2 = Atom(symbol='Al')
    at3 = Atom(symbol="Zr")

    site1 = Site((0, 0, 0), at1)
    site2 = Site((0.5, 0.5, 0.5), at2)
    site3 = Site((0.5, 0.5, 0.0), at3)
    site4 = Site((0.5, 0.0, 0.5), at3)
    site5 = Site((0.0, 0.5, 0.5), at3)

    uc.addSite(site1, "Fe1")
    uc.addSite(site2, "Al1")
    uc.addSite(site3, "")
    uc.addSite(site4, "")
    uc.addSite(site5, "")

    print "\n Original unit cell with 3 equivalent Zr atoms:\n"

    for key in uc._siteIds.keys():
        print key, uc._siteIds[key]

    uc.getSiteFromId("Id0").getAtom().magneticMoment = 1.2

    print "\n Modified unit cell with changed Zr magnetic moment:\n"

    for key in uc._siteIds.keys():
        print key, uc._siteIds[key]
    return
def test():
    from UnitCell import UnitCell, Site
    from Atom import Atom

    uc = UnitCell()
    at0 = Atom(symbol="Al")
    at1 = Atom(symbol="Fe")
    site0 = Site([0.0, 0.0, 0.0], at0)
    site1 = Site([0.5, 0.5, 0.5], at1)
    uc.addSite(site0, "")
    uc.addSite(site1, "")
    print uc
    print

    from python.parsing.parse_phon_results import parse
    phonlist = parse("phon.out_dos_noIBZ")

    wvectors = [[qx, 0.0, 0.0] for qx in range(30)]

    dwc = DebyeWallerCalculator(uc, phonlist, phonlist)

    dwlist = [
        dwc.getDWFactorForAtom(0, wavevector, 300) for wavevector in wvectors
    ]
    #print dwlist
    return dwlist
Esempio n. 3
0
def fccBravaisCell():
    s = AtomSystem()
    #...lattice
    alc = 1.0
    a1 = np.array([1.0, 0.0, 0.0])
    a2 = np.array([0.0, 1.0, 0.0])
    a3 = np.array([0.0, 0.0, 1.0])
    s.set_lattice(alc, a1, a2, a3)
    #...atom1
    atom = Atom()
    atom.set_pos(0.0, 0.0, 0.0)
    atom.set_sid(1)
    s.add_atom(atom)
    #...atom2
    atom = Atom()
    atom.set_pos(0.5, 0.5, 0.0)
    atom.set_sid(1)
    s.add_atom(atom)
    #...atom3
    atom = Atom()
    atom.set_pos(0.5, 0.0, 0.5)
    atom.set_sid(1)
    s.add_atom(atom)
    #...atom4
    atom = Atom()
    atom.set_pos(0.0, 0.5, 0.5)
    atom.set_sid(1)
    s.add_atom(atom)
    return s
Esempio n. 4
0
def gen_atom(n):
    rad = np.random.randint(1, 5)
    atomy = [
        Atom(v=Vec2(np.random.randint(75), np.random.randint(75)),
             pos=Vec2(np.random.randint(5, 40), np.random.randint(5, 40)),
             r=rad,
             m=rad * 10)
    ]
    i = 0
    while len(atomy) < n:
        x = np.random.randint(5, 40)
        y = np.random.randint(5, 40)
        p = Vec2(x, y)
        rad = np.random.randint(1, 5)
        flaga = 0
        for atom in atomy:
            odl = dc(atom.pos) - p
            if odl.length() < atom.r + rad:
                flaga += 1
        if flaga == 0:
            mass = rad * 10
            atomy.append(
                Atom(v=Vec2(np.random.randint(75), np.random.randint(75)),
                     pos=p,
                     r=rad,
                     m=mass))
    return atomy
Esempio n. 5
0
def uc_test2():
    print "\n*** test2 ***"
    cellvectors = [(1, 0, 0), (0, 1, 0), (0, 0, 1)]
    uc = create_unitcell(
        cellvectors, [Atom(symbol='Fe'), Atom(symbol='Al')], [(0, 0, 0),
                                                              (0.5, 0.5, 0.5)])
    print uc
    return
Esempio n. 6
0
def test():
    a = InputMOLPRO('test.com')
    at1 = Atom(symbol='O', position=[0.0, 0.0, 0.0]) 
    at2 = Atom(symbol='H', position=[2.0, 0.0, 0.0]) 
    at3 = Atom(symbol='H', position=[0.0, 2.0, 0.0]) 
    a.set_option('symmetry,nosym\n') 
    a.set_method('hf\nforces\n') 
    a.set_coordinate([at1,at2,at3]) 
    a.make_input() 
    a.write()
Esempio n. 7
0
def test():
    from Atom import Atom
    from Molecule import Molecule 
    from IO_MOLPRO import InputMOLPRO 
    at1 = Atom(symbol='H', position=[2,0,0])
    at2 = Atom(symbol='H', position=[0,0,0])
    mol = Molecule([at1,at2])
    inp = InputMOLPRO()
    pot = Potential_QM(mol,inp)
    pot.calc()
Esempio n. 8
0
def test3():
    from Atom import Atom
    from Molecule import Molecule
    from VelocityVerlet import VelocityVerlet
    from Constants import fs2tau

    at1 = Atom(symbol='Ar', position=[5,0,0])
    at2 = Atom(symbol='Ar', position=[0,0,0])
    at3 = Atom(symbol='Ar', position=[0,5,0])
    mol = Molecule([at1,at2,at3])
    pot = Potential_MM(mol)
    md = VelocityVerlet(mol,pot,deltat=0.5*fs2tau ,nstep=200)
    md.run() 
Esempio n. 9
0
    def __init__(self, score):
        "Initialises resources and start level"

        self.atoms = pygame.sprite.Group()
        self.ntype = 2  #number of atom classes
        self.level = 2

        for i in range(10):
            self.atoms.add(Atom((random(), random()), "green", 1.0, self))

        for i in range(10):
            self.atoms.add(Atom((random(), random()), "blue", 1.0, self))

        Level.__init__(self, score, 75)
Esempio n. 10
0
 def isTypeOG304(self, mol, atm_index):
     atom = mol.atoms[atm_index]
     atom_linked_1 = Atom()
     atom_linked_2 = Atom()
     if atom.num_linkages == 2:
         atom_linked_1 = mol.atoms[atom.linkage[0]]
         atom_linked_2 = mol.atoms[atom.linkage[1]]
         if (atom_linked_1.element.lower() == "P".lower()
                 or atom_linked_1.element.lower()
                 == "S".lower()) and atom_linked_1.numOxygenAtoms == 4:
             if (atom_linked_2.element.lower() == "P".lower()
                     or atom_linked_2.element.lower()
                     == "S".lower()) and atom_linked_2.numOxygenAtoms == 4:
                 return True
     return False
Esempio n. 11
0
def parse(tokens):
    syntax_tree = list()

    #if we have no tokens at start, there is an error
    if len(tokens) is 0:
        raise SyntaxError("Expected tokens")

    #get current token and take it off tokens list
    cur_token = tokens.pop(0)

    #if we get a ) token, then there is an error
    # ) shouldnt come before (
    if cur_token is ")":
        raise SyntaxError("Expected (")

    #if we get a ( then recursivley call parse, adding the output to our parse tokens list
    elif cur_token is "(":
        #loop until we get a ), ending the list
        while tokens[0] is not ")":
            syntax_tree.append(parse(tokens))

        #once we get a ), remove it from the tokens list and return the syntax tree
        tokens.pop(0)
        return syntax_tree

    #if none of the above, token is an atom
    #create an atom and return it
    else:
        atom = Atom(cur_token)
        return atom
Esempio n. 12
0
    def parse_atom_line(self,
                        line):  # parses an atom line, returns an atom object
        record_name = line[:6]
        serial_number = line[6:11]
        atom_name = line[11:17]
        alt_loc = line[16:17]
        residue_name = line[17:20]
        chain_id = line[20:22]
        residue_number = line[22:26]
        icode = line[26:30]
        x_coord = line[30:38]
        y_coord = line[38:46]
        z_coord = line[46:54]
        occupancy = line[54:60]
        bfactor = line[60:66]
        element = line[66:78]
        charge = line[78:]
        #troubleshooting
        #print(record_name+","+serial_number+","+atom_name+","+alt_loc+","+res_name+","+chain_id+","+res_seq+","+icode+","+xcoord+","+ycoord+","+zcoord+","+occupancy+","+bfactor+","+element+","+charge+",")
        atom = Atom(record_name, serial_number, atom_name, alt_loc,
                    residue_name, chain_id, residue_number, icode, x_coord,
                    y_coord, z_coord, occupancy, bfactor, element, charge)

        #print(record_name,serial_number,atom_name,alt_loc,residue_name,chain_id,residue_number,icode,x_coord,y_coord,z_coord,occupancy,bfactor,element,charge)
        return atom
Esempio n. 13
0
    def initializeAtomData(self):
        """ Return dictionary of atomData based on all symbols in SMILES code.

            Atom objects are created based on the symbol and index position of that atom
            Handles charges and finds valid alcohol indices
        """

        atomData = {}
        atomIndex = -1  # 0 based indexing of atoms

        for pos, symbol in enumerate(self.SMILES):

            if symbol in self.ATOMS:  # Exclusively analyze atoms
                atomIndex += 1
                atomSymbol = symbol

                if self.SMILES[
                        pos -
                        1] == '[':  # If atom charged, collect its bracketed group
                    atomSymbol = self.getChargedGroup(
                        pos - 1)  # Use opening bracket for charge group

                atom = Atom(atomIndex, atomSymbol)  # Create new atom objects
                atomData[atomIndex] = atom  # Atom index to atom object pairing

                if symbol == 'O':  # Alochols stem from oxygens
                    self.determineAlcoholGroup(pos, atomIndex)

        return atomData
 def read_atoms(self,f):
     for line in f:
         if line.isspace(): break
         if line[0] == ';': continue
         line = line.split()
         atom = Atom(line[0],line[1],line[2],line[3],line[4],line[5],line[6],line[7])
         self.atom_list.append(atom)
Esempio n. 15
0
def branch_state(state, merits):

    # New walkers
    branch_walkers = []

    for i in range(state.nbr_of_walkers):

        # Make m-1 copies of each walker
        nbr_of_copies = merits[i]

        # Append all copies of these walkers
        for _ in range(nbr_of_copies):

            branch_walkers.append(state.walkers[i])


        # Re-number all walkers
        for walker, i in zip(branch_walkers, range(len(branch_walkers))):
            walker.id = i


    # Create new state
    new_state = Atom(alpha = state.alpha,
                    walkers = branch_walkers,
                    element = state.element,
                    dims = state.dims)

    return new_state
Esempio n. 16
0
    def read_pdbqt(self, filename):
        with open(filename, 'r') as p_file:
            branch_stack = []
            current_branch = None
            # Like atom ID, branch ID starts from 1.
            branch_id = 1
            for line in p_file:
                # HETATM
                if line.startswith("HETATM"):
                    data = line.split()
                    atom_id = int(data[1])
                    tcoord = Axis3(float(data[6]), \
                                   float(data[7]), \
                                   float(data[8]))
                    current_branch = branch_stack[-1]
                    atom = Atom(atom_id, data[12], tcoord, float(data[11]), \
                                current_branch)
                    self.ori_atoms.append(atom)
                    # Update atom id into current active branches
                    # Note: First branch is root but when collecting atoms, it
                    # is treated as a branch)
                    for branch in branch_stack:
                        if atom_id != branch.link_id:
                            branch.all_atom_ids.append(atom_id)
                    if atom_id != branch_stack[-1].link_id:
                        branch_stack[-1].atom_ids.append(atom_id)
                # ROOT
                elif line.startswith("ROOT"):
                    # Ligand has only one root. Always set the ID to 1.
                    self.root = Branch(branch_id, None, None, [], [], None, [])
                    branch_id += 1
                    # Push root into branch_stack
                    branch_stack.append(self.root)
                # ENDROOT
                elif line.startswith("ENDROOT"):
                    branch_stack.pop()
                # BRANCH
                elif line.startswith("BRANCH"):
                    anchor_id, link_id = [int(x) for x in line.split()[1:]]
                    # Get parent branch from the stack (which is the last one).
                    # If it empty, it means this branch directly linked to the
                    # root.
                    if not branch_stack:
                        parent_branch = self.root
                    else:
                        parent_branch = branch_stack[-1]
                    branch = Branch(branch_id, anchor_id, link_id, [], \
                                    [], parent_branch, [])
                    # Now the parent branch has this branch as the child
                    parent_branch.children.append(branch)
                    self.branches.append(branch)
                    # Push active branch into branch_stack
                    branch_stack.append(branch)
                    branch_id += 1
                # ENDBRANCH
                elif line.startswith("ENDBRANCH"):
                    # Pop inactive branch from branch_stack
                    branch_stack.pop()

        self.reset_atoms()
Esempio n. 17
0
 def __init__(self, atomname, estimate_num, dens):
     self.atomname = atomname
     self.n = estimate_num
     mass = Atom(symbol=self.atomname).GetMass()
     self.numdens = dens / 9.10939e-4 / mass / ang2bohr**3
     self.vlength = (self.n / self.numdens)**(1.0 / 3.0)
     self.make_lattice()
Esempio n. 18
0
def make_trial_state(state, timestep):
    """ Creates a trial state by generating trial walkers from driven diffusion.
    
    Arguments:
        state {Atom} -- An atom state from the previous iteration.
        timestep {double} -- Size of the time step of each iteration.
    
    Returns:
        Atom -- A trial state with updated walker positions from diffusion.
    """

    new_walkers = []
    
    for walker in state.walkers:
            
        # Calculate new position based on former walker
        new_walker = make_trial_walker(walker, timestep)
            
        # Add new walker to set
        new_walkers.append(new_walker)


    # Create new trial state to compare with previous
    trial_state = Atom(alpha = state.alpha,
                       walkers = new_walkers,
                       element = state.element,
                       dims = state.dims) 

    # Update the id of the newest walker, for plotting purposes
    trial_state.max_walker_id = state.max_walker_id

    return trial_state
Esempio n. 19
0
 def read_pmd(self, fname='pmd0000'):
     f = open(fname, 'r')
     # 1st: lattice constant
     self.alc = float(f.readline().split()[0])
     # 2nd-4th: cell vectors
     for i in range(3):
         data = f.readline().split()
         self.a1[i] = float(data[0])
         self.a2[i] = float(data[1])
         self.a3[i] = float(data[2])
     # self.a1= np.array([float(x) for x in f.readline().split()])
     # self.a2= np.array([float(x) for x in f.readline().split()])
     # self.a3= np.array([float(x) for x in f.readline().split()])
     # 5th-7th: velocity of cell vectors
     tmp = f.readline().split()
     tmp = f.readline().split()
     tmp = f.readline().split()
     # 8st: num of atoms
     natm = int(f.readline().split()[0])
     # 9th-: atom positions
     self.atoms = []
     for i in range(natm):
         data = [float(x) for x in f.readline().split()]
         ai = Atom()
         ai.decode_tag(data[0])
         ai.set_pos(data[1], data[2], data[3])
         ai.set_vel(data[4], data[5], data[6])
         self.atoms.append(ai)
     f.close()
Esempio n. 20
0
    def test2(self):
        uc = UnitCell()
        
        uc.addAtom(Atom('H', (0,0,0.1)))
        
        self.assert_(uc.hasAtom(Atom('H', (0,0,0.10000001))))
        self.assert_(uc.hasAtom(Atom('H', (0,0,0.09999999))))
        self.assert_(not uc.hasAtom(Atom('H', (0,0,0.11))))
        self.assert_(not uc.hasAtom(Atom('H', (0,0,0.09))))

        self.assert_(uc.hasAtom(Atom('H', (0,0,1.10000001))))
        self.assert_(uc.hasAtom(Atom('H', (0,0,1.09999999))))
        self.assert_(not uc.hasAtom(Atom('H', (0,0,1.11))))
        self.assert_(not uc.hasAtom(Atom('H', (0,0,1.09))))
        self.assert_(not uc.hasAtom(Atom('H', (0,0,1.09999))))
        return
Esempio n. 21
0
 def setAtomTypeForMiscellaneousAtoms(self, mol):
     num_atoms = len(mol.atoms)
     atom = Atom()
     atom_linked = Atom()
     index = -1
     i = 0
     while i < num_atoms:
         atom = mol.atoms[i]
         if atom.element.lower() == "P".lower():
             if atom.numSulfurAtoms == 0:
                 charge = self.getCharge(mol, i)
                 if charge == 0:
                     #  PG0: neutral phosphate
                     atom.atomType = "PG0"
                 elif charge == -1:
                     #  PG1: phosphate -1
                     atom.atomType = "PG1"
                 elif charge == -2:
                     #  PG2: phosphate -2
                     atom.atomType = "PG2"
             else:
                 j = 0
                 while j < atom.num_linkages:
                     atom_linked = mol.atoms[atom.linkage[j]]
                     if atom_linked.element.lower() == "O".lower(
                     ) and atom_linked.num_linkages == 1:
                         #  OG2S1: mono-thio S-P bond modulated oxygen; lsk
                         atom_linked.atomType = "OG2S1"
                     j += 1
         elif atom.element.lower() == "LP".lower():
             #  LPH: Lone pair for halogens
             atom.atomType = "LPH"
         elif atom.element.lower() == "AL".lower():
             if self.countSpecificElement(mol, i, "F") == 4:
                 #  ALG1: Aluminum, for ALF4, AlF4-
                 atom.atomType = "ALG1"
         elif atom.element.lower() == "S".lower():
             if atom.num_linkages == 1:
                 atom_linked = mol.atoms[atom.linkage[0]]
                 if atom_linked.element.lower() == "P".lower():
                     if num_S == 1:
                         #  SG2P1: mono-thio S-P bond; lsk
                         atom.atomType = "SG2P1"
                     elif num_S == 2:
                         #  SG2P2: di-thio S-P bond; lsk
                         atom.atomType = "SG2P2"
         i += 1
Esempio n. 22
0
    def __init__(self, score):
        "Initialises resources and start level"

        self.atoms = pygame.sprite.Group()
        self.ntype = 2  #number of atom classes
        self.level = 1

        for i in range(4):
            self.atoms.add(Atom((random(), random()), "green", 1.0, self))

        for i in range(4):
            self.atoms.add(Atom((random(), random()), "blue", 1.0, self))

        Level.__init__(self, score, 35)

        pygame.mixer.music.load("music/menu.ogg")
        pygame.mixer.music.play(-1)
Esempio n. 23
0
def uc_test1():
    print "\n*** test1 ***"
    uc = UnitCell()
    at1 = Atom(symbol='Fe', mass=57)
    pos1 = (0.0, 0.0, 0.0)
    at2 = Atom(symbol='Al')
    pos2 = (0.5, 0.5, 0.5)

    site1 = Site(pos1, at1)
    site2 = Site(pos2, at2)

    uc.addAtom(at1, pos1, "Fe1")
    uc.addAtom(at2, pos2, "Al1")
    for site in uc:
        print "\n position %s \n %s" % (site.getPosition(), site.getAtom())
        continue
    return
Esempio n. 24
0
 def __copy__(self):
     new = UnitCell()
     new._lattice = self._lattice
     for siteId in self._siteIds.keys():
         newsite = Site(self._siteIds[siteId].getPosition(),
                        Atom(Z=self._siteIds[siteId].getAtom().Z))
         new.addSite(newsite, siteId=siteId)
     return new
Esempio n. 25
0
    def __init__(self, atomnames = [], atomnumbers = [], positions = None, velocities = None,\
            forces = None, ndims = 3):
        assert atomnames != [] or atomnumbers != [], "define atomic symbols or atomic numbers"

        self.atomnames, self.atomnumbers = [], []
        self.masses = []
        self.ndims = ndims

        if atomnames != []:
            self.atomnames = [atom.lower().capitalize() for atom in atomnames]
            for atom in self.atomnames:
                self.masses.append(Atom(symbol=atom).GetMass())
                self.atomnumbers.append(Atom(symbol=atom).GetAtomicNumber())

        if atomnumbers != []:
            self.atomnumbers = atomnumbers
            for natom in self.atomnumbers:
                self.masses.append(Atom(Z=natom).GetMass())
                self.atomnames.append(Atom(Z=natom).GetChemicalSymbol())

        self.atomnames = np.array(self.atomnames)
        self.atomnumbers = np.array(self.atomnumbers)
        self.masses = np.array(self.masses)
        self.natoms = len(self.atomnames)

        if positions == None:
            self.positions = np.zeros((self.natoms, self.ndims))
        else:
            assert np.shape(positions) == (
                self.natoms, self.ndims), "Molecule class size error"
            self.positions = np.array(positions)

        if velocities == None:
            self.velocities = np.zeros((self.natoms, self.ndims))
        else:
            assert np.shape(velocities) == (
                self.natoms, self.ndims), "Molecule class size error"
            self.velocities = np.array(velocities)

        if forces == None:
            self.forces = np.zeros((self.natoms, self.ndims))
        else:
            assert np.shape(forces) == (
                self.natoms, self.ndims), "Molecule class size error"
            self.forces = np.array(forces)
Esempio n. 26
0
    def addNewAtom(self, *args, **kwargs):
        """Add new Atom instance to the end of this Structure.

        All arguments are forwarded to Atom constructor.
        """
        kwargs['lattice'] = self.lattice
        a = Atom(*args, **kwargs)
        list.append(self, a)
        self._uncache('labels')
Esempio n. 27
0
def insert_quote(syntax_tree):
    #loop through all expressions in the tree
    for index, expr in enumerate(syntax_tree):
        #if the expression is a list, recursivley call insert_quote on the list
        if isinstance(expr, list):
            insert_quote(expr)
        #if the expression is the ' atom, replace it with (quote symbol)
        elif expr.data is "'":
            syntax_tree[index] = [Atom("quote"), syntax_tree[index + 1]]
            syntax_tree.pop(index + 1)
Esempio n. 28
0
 def setAtomTypeForSulfurs(self, mol):
     num_atoms = len(mol.atoms)
     atom = Atom()
     atom_linked = Atom()
     index = -1
     i = 0
     while i < num_atoms:
         atom = mol.atoms[i]
         if atom.element.lower() == "S".lower():
             atom_linked = mol.atoms[atom.linkage[0]]
             if atom.num_linkages == 2:
                 #  SG311: sulphur, SH, -S-
                 atom.atomType = "SG311"
             if not atom.isRingAtom:
                 if atom.isThiocarbonylS:
                     #  SG2D1: thiocarbonyl S
                     atom.atomType = "SG2D1"
                 elif atom.num_linkages == 2 and atom.numSulfurAtoms == 1 and atom.numCarbonAtoms == 1:
                     #  SG301: sulfur C-S-S-C type
                     atom.atomType = "SG301"
                 elif atom.isDeprotonatedSulfur:
                     #  SG302: thiolate sulfur (-1)
                     atom.atomType = "SG302"
                 elif atom.num_linkages == 3 and atom.numCarbonAtoms == 2 and atom.numOxygenAtoms == 1:
                     #  SG3O3: neutral sulfoxide sulfur
                     atom.atomType = "SG3O3"
                 if atom.numOxygenAtoms >= 2:
                     charge = self.getCharge(mol, i)
                     if charge == -1:
                         #  SG3O1: sulfate -1 sulfur
                         atom.atomType = "SG3O1"
                     elif charge == 0:
                         #  SG3O2: neutral sulfone/sulfonamide sulfur
                         atom.atomType = "SG3O2"
             else:
                 if atom.numOxygenAtoms >= 2 and self.getCharge(mol,
                                                                i) == 0:
                     #  SG3O2: neutral sulfone/sulfonamide sulfur
                     atom.atomType = "SG3O2"
                 elif atom.numRingAtoms[0] == 5:
                     #  SG2R50: THIP, thiophene
                     atom.atomType = "SG2R50"
         i += 1
Esempio n. 29
0
 def read_atoms(self, f):
     for line in f:
         if line.isspace(): break
         if line[0] == ';': continue
         line = line.split()
         atom = Atom(line[0], line[1], line[2], line[3], line[4], line[5], line[6], line[7])
         if len(line) > 8:
             if line[8] == "AR":
                 atom.set_aromatic()
         self.atom_list.append(atom)
Esempio n. 30
0
 def isTypeNG3N1(self, mol, atm_index):
     atom = mol.atoms[atm_index]
     atom_linked = Atom()
     if atom.num_linkages == 3:
         index = self.getIndexElement(mol, atm_index, "N")
         if index != -1:
             atom_linked = mol.atoms[index]
             if atom_linked.numHydrogenAtoms == 2 or atom_linked.numHydrogenAtoms == 1:
                 return True
     return False