def attach(partmono, attach1, monomer, number): # needs more work, very specific right now monomernew = monomer num = int(number) for run in range(0, num): add = int(monomernew.atoms[-1].atom_id) newalist = [] newblist = [] # remove bonds in old attach and remove the hydrogen as well for i in range(len(attach1.atom_bonds)): if attach1.atom_bonds[i].atom_type == "H": # this has to do in a specific manner, may have to change oldh = attach1.atom_bonds[i] attachid = attach1.atom_id abond = bond.get_bond(attach1, oldh, monomernew.bonds) monomernew.bonds.remove(abond) monomernew.atoms.remove(oldh) # take partmono and offset all of its atoms to create a good atomlist for i in range(len(partmono)): newalist.append(copy.deepcopy(partmono[i])) newalist[i].atom_id = int(partmono[i].atom_id) + add newalist[i].x_pos = float(newalist[i].x_pos) + (run + 1) * -4.000 print (run + 1) * 5.000 # generate new alist, put this kind of stuff into one big method or something for i in range(len(newalist)): for j in range(len(newalist[i].atom_bonds)): newalist[i].atom_bonds[j] = atom.get_atombyid(newalist, int(newalist[i].atom_bonds[j].atom_id) + add) # generate new blist newblist = getpartblist(partmono, monomer, newalist, add) for i in range(len(newblist)): if newblist[i].bond_slave == None: newblist.remove(newblist[i]) break a5add = atom.get_atombyid(newalist, 5 + add) a37add = atom.get_atombyid(newalist, 37 + add) newblist.append(bond.Bond(1, a5add, a37add)) # remove the nonetype from addloc so it doesnt f**k shit up # add this to newmonomer for i in range(len(newalist)): monomernew.atoms.append(newalist[i]) for i in range(len(newblist)): monomernew.bonds.append(newblist[i]) print newalist[0].atom_id print monomer.atoms[0].atom_id print newalist[0].atom_bonds[1].atom_id print newblist[0].bond_master.atom_id print newalist[0].x_pos print monomer.atoms[0].x_pos attach1 = atom.get_atombyid(newalist, int(attachid) + add) return monomernew
def set_dft(dihedral,bonds): """ Given a list of dihedrals find if you should set dft values for those dihedrals or not. Sets a boolean on the list of dihedrals that need dft calculations done to them. Probably should return a list instead for speed optimization Keyword Arguments: dihedral - The list of dihedrals you want to check bonds - The list of bonds you want to check """ for i in range(len(dihedral)): mb1 = bond.get_bond(dihedral[i].dihedral_master1,dihedral[i].dihedral_master2,bonds) if mb1.bond_type == '1': ob1 = bond.get_bond(dihedral[i].dihedral_master1,dihedral[i].dihedral_slave1,bonds) ob2 = bond.get_bond(dihedral[i].dihedral_master2,dihedral[i].dihedral_slave2,bonds) if ob1 == None or ob2 == None: continue if ob1.bond_type == '2' and ob2.bond_type == '2': dihedral[i].dft = True
def create_polymer_cml(filename, partmono, attach, monomer, number): """ Basically a test for writing a cml from data and creating a 3rd attach""" new_cml = open("%s_new.cml" % filename, "w") sys.stdout = new_cml usedbonds = [] bondscopy = [] for i in range(len(monomer.bonds)): bondscopy.append(monomer.bonds[i]) for i in range(len(attach.atom_bonds)): if attach.atom_bonds[i].atom_type == "H": attach2 = attach.atom_bonds[i] abond = bond.get_bond(attach, attach2, monomer.bonds) monomer.bonds.remove(abond) monomer.atoms.remove(attach2) # find the hydrogen its attached to and remove instead add = len(monomer.atoms) + 1 newattach = "" anglelist = monomer.angles # THIS SHIT IS USELESS. DONT USE FOR ATTACH MODULE for i in range(len(anglelist)): if ( anglelist[i].Angle_master.atom_type == "C" and anglelist[i].Angle_slave1.atom_type == "C" and anglelist[i].Angle_slave2.atom_type == "S" and anglelist[i].Angle_master in partmono and anglelist[i].Angle_slave1 in partmono and anglelist[i].Angle_slave2 in partmono ): newattach = anglelist[i].Angle_master elif ( anglelist[i].Angle_master.atom_type == "C" and anglelist[i].Angle_slave1.atom_type == "S" and anglelist[i].Angle_slave2.atom_type == "C" and anglelist[i].Angle_master in partmono and anglelist[i].Angle_slave1 in partmono and anglelist[i].Angle_slave2 in partmono ): newattach = anglelist[i].Angle_master print "<molecule>" print " <atomArray>" for i in range(len(monomer.atoms)): print ' <atom id="a%s" elementType="%s" x3="%s" y3="%s" z3="%s"/>' % ( monomer.atoms[i].atom_id, monomer.atoms[i].atom_type, monomer.atoms[i].x_pos, monomer.atoms[i].y_pos, monomer.atoms[i].z_pos, ) for i in range(len(partmono)): print ' <atom id="a%s" elementType="%s" x3="%s" y3="%s" z3="%s"/>' % ( int(partmono[i].atom_id) + add, partmono[i].atom_type, float(partmono[i].x_pos) - 5.00, float(partmono[i].y_pos), float(partmono[i].z_pos), ) print " </atomArray>" print " <bondArray>" for i in range(len(monomer.bonds)): print ' <bond atomRefs2="a%s a%s" order="%s"/>' % ( monomer.bonds[i].bond_master.atom_id, monomer.bonds[i].bond_slave.atom_id, monomer.bonds[i].bond_type, ) for i in range(len(partmono)): for j in range(len(partmono[i].atom_bonds)): if partmono[i].atom_bonds[j] in partmono: bondid = bond.get_bond(partmono[i], partmono[i].atom_bonds[j], bondscopy) if bondid in usedbonds: continue usedbonds.append(bondid) print ' <bond atomRefs2="a%s a%s" order="%s"/>' % ( int(partmono[i].atom_id) + add, int(partmono[i].atom_bonds[j].atom_id) + add, bondid.bond_type, ) else: continue print ' <bond atomRefs2="a%s a%s" order="1"/>' % (attach.atom_id, int(newattach.atom_id) + add - 2) print " </bondArray>" print "</molecule>" new_cml.close()