def main(): """ reports the number of residues in a pdbfile """ parser = OptionParser() parser.add_option("-p", dest="pdbfile", help="pdbfile") parser.add_option("-P", dest="pdblist", help="pdblist") parser.add_option("-x", dest="cutoff", help="cutoff", default=3.0) parser.add_option("-n", dest="native", help="native") parser.set_description(main.__doc__) (options, args) = parser.parse_args() pdbfiles = [] if options.pdblist: pdbfiles = files_from_list(options.pdblist) elif options.pdbfile: pdbfiles.append(options.pdbfile) else: parser.print_help() sys.exit() if not options.cutoff: parser.print_help() sys.exit() nat_mol = None if options.native: nat_mol = Molecule() nat_mol.readPDB(options.native) nat_seq = nat_mol.sequence() re_complete = re.compile("complete") rama_cutoff = float(options.cutoff) for pdbfile in pdbfiles: try: PDB = open(pdbfile) except: print "unable to open pdbfile" sys.exit() bRead = False for line in PDB.readlines(): if re_complete.match(line): bRead = True continue if bRead: cols = line.split() if len(cols) < 10: bRead = False continue eRama = float(cols[6]) if eRama > rama_cutoff: if options.native: print pdbfile, cols[0], cols[7], eRama, nat_seq[ int(cols[0]) - 1] else: print pdbfile, cols[0], cols[7], eRama
def main(): """ reports the formal charge of a pdbfile where ASP/GLU are -1 and LYS/ARG are +1 """ parser = OptionParser() parser.add_option("-p", dest="pdbfile", help="pdbfile") parser.set_description(main.__doc__) (options, args) = parser.parse_args() if not options.pdbfile: parser.print_help() sys.exit() protein = Molecule() protein.readPDB(options.pdbfile) charge = 0.0 for chain in protein.chain: for residue in chain.residue: if residue.name == "ASP" or residue.name == "GLU": charge -= 1.0 if residue.name == "LYS" or residue.name == "ARG": charge += 1.0 print("Charge = %5.1f" % charge)
def readData(self): """ Function doc """ molecule = Molecule(name=self.filename) f = open(self.filename, 'r') for line in f.readlines(): if line[0:4] == 'ATOM' or line[0:6] == 'HETATOM': atom = self._readAtom(line) molecule.atoms[atom.id] = atom if line[0:6] == 'CONECT': #print line pass bonds_in_line = self._readBonds(line) for bond in bonds_in_line: molecule.bonds.append(bond) f.close() #if the pdb had no bond information we should calculate them ########################################## if len(molecule.bonds ) == 0: # esta funcao precisa ser otimizada # #pass # esta funcao precisa ser otimizada # molecule.bonds = self._calcBonds( molecule.atoms) # esta funcao precisa ser otimizada # ########################################## self.molecules.append(molecule)
def main(): """ creates a poly-glycine variant of a pdbfile by removing all sidechains """ parser = OptionParser() parser.add_option("-p", dest="pdbfile", help="pdbfile") parser.add_option("-o", dest="outfile", help="outfile") parser.add_option("-r", dest="replace", help="replace", action="store_true") parser.set_description(main.__doc__) (options, args) = parser.parse_args() if not options.pdbfile or not options.outfile: parser.print_help() sys.exit() selection = Selection() selection.makeSelection("BB") protein = Molecule() protein.readPDB(options.pdbfile) newmol = selection.apply_selection(protein) for chain in newmol.chain: for res in chain.residue: res.name = "GLY" newmol.writePDB(options.outfile)
def tube_through_atoms(atoms, radius = 0, band_length = 0, segment_subdivisions = 10, circle_subdivisions = 15, follow_bonds = True, color = None, surface_model = None, model_id = None): if len(atoms) == 0: return None, [] if follow_bonds: chains = atom_chains(atoms) else: chains = [(atoms,None)] if color is None: color = (1,1,1,1) s = surface_model sxf = (s or atoms[0].molecule).openState.xform plist = [] import Molecule as M for atoms, bonds in chains: xyz_path = M.atom_positions(atoms, sxf) point_colors = [M.atom_rgba(a) for a in atoms] if bonds is None: segment_colors = [color] * (len(atoms) - 1) else: segment_colors = [M.bond_rgba(b) for b in bonds] p = banded_tube(xyz_path, point_colors, segment_colors, radius, segment_subdivisions, circle_subdivisions, band_length, surface_model = s, model_id = model_id) if p: plist.append(p) s = p.model if s: s.openState.xform = sxf return s, plist
def testRepDuplication(self): m0a = Molecule(id=self.mol1.id) m0b = Molecule(id=self.mol1.id) reps=m0a.reps() test1=lambda: m0a.addRep(reps[0]) test2=lambda: m0b.addRep(reps[0]) self.failUnlessRaises(ValueError, test1) self.failUnlessRaises(ValueError, test2)
def __init__(self, pdbfilename=None, VMD_atomsel=None, tempdir=None, path='/home/armeev/Software/Source/x3dna-v2.1'): if (tempdir == None): os.mkdir('temp') self.TEMP = 'temp' else: self.TEMP = tempdir self.set_3dna_path(path) self.AVERAGE, self.FORCE_CONST, self.DISP, self.lbl1, self.lbl2 = get_consts( ) self.lbl1_ref = self.lbl1.select(''' name C5' C4' C3' C2' C1' O4' ''') self.lbl2_ref = self.lbl2.select(''' name C5' C4' C3' C2' C1' O4' ''') self.lbl1_com = self.lbl1.select(''' name COM ''') self.lbl2_com = self.lbl2.select(''' name COM ''') #confProDy(verbosity='none') #copying some files for backbone reconstruction cmd = self.P_X3DNA_utils + ' cp_std BDNA' p = subprocess.Popen(cmd, shell=True, cwd=self.TEMP, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = p.communicate() self.pairs_id = '' self.distCoef = 0.1 if VMD_atomsel != None: if NOVMD: print "VMD Libs aren't avaiable" return DNA = VMD_atomsel pairparam = self.X3DNA_find_pair(DNA_atomsel=DNA) elif pdbfilename != None: pairparam = self.X3DNA_find_pair(pdbfile=pdbfilename) else: print "You must provide VMD atomsel or pdb filename" return self.par_header, self.par_pairs, self.par_frame = self.X3DNA_analyze( pairparam) if VMD_atomsel != None: if NOVMD: print "VMD Libs aren't avaiable" return self.frame_to_pdb(self.par_frame, 'init_rebuilt.pdb') self.mol = Molecule() self.mol.load(self.TEMP + '/init_rebuilt.pdb') self.num_of_res = self.par_frame.shape[0] self.set_movable_bp([[1, self.num_of_res]])
def main(): """ given a match output file creates an output file of the catalytic site only """ parser = OptionParser() parser.add_option("-p", dest="pdbfile", help="pdbfile") parser.add_option("-o", dest="outfile", help="outfile") parser.set_description(main.__doc__) (options, args) = parser.parse_args() if not options.outfile or not options.pdbfile: parser.print_help() sys.exit() # read remark remark = re.compile("REMARK") try: pdb = open(options.pdbfile) except: print "unable to open pdbfile" sys.exit() resline = "resi=" read = False for line in pdb.readlines(): if remark.match(line): cols = line.split() resi = cols[5] if read: resline += "," resline += resi read = True pdb.close() selection = Selection() selection.makeSelection(resline) # --- extract out the residue selections --- # protein = Molecule() protein.readPDB(options.pdbfile) newmol = selection.apply_selection(protein) selection.clear() # --- extract out the hetero atoms --- # selection.makeSelection("type=HETATM") hetatm = selection.apply_selection(protein) reslist = hetatm.residueList() newchain = newmol.newChain() newchain.addResidueList(reslist) newmol.writePDB("dumb.pdb")
def add(self,code,pdb,topology=-1): if code in self.molecules.keys(): self.logger.warning("\n> WARNING: residue %s already present in database. Overwriting."%code) try: self.logger.info(">> loading PDB %s"%pdb) m=Molecule() m.import_pdb(pdb, "gromacs") except Exception,e: raise IOError(e)
def extrusion_transforms(ptlist): import Matrix as M tflist = [] tf = M.identity_matrix() n0 = (0,0,1) for p1,n1 in ptlist: tf = M.multiply_matrices(M.vector_rotation_transform(n0,n1), tf) tflist.append(M.multiply_matrices(M.translation_matrix(p1),tf)) n0 = n1 return tflist
def extrusion_transforms(ptlist): import Matrix as M tflist = [] tf = M.identity_matrix() n0 = (0, 0, 1) for p1, n1 in ptlist: tf = M.multiply_matrices(M.vector_rotation_transform(n0, n1), tf) tflist.append(M.multiply_matrices(M.translation_matrix(p1), tf)) n0 = n1 return tflist
def testPickle(self): import pickle m=Molecule() file1='../proteins/alanin.psf' file2='../proteins/alanin.dcd' m.load(file1) m.load(file2) f=open('test.pkl', 'w') pickle.dump(m, f) f.close() g=open('test.pkl', 'r') m2=pickle.load(g)
def main(): """ trims a grid for a given selection and cutoff values """ parser = OptionParser() parser.add_option("-p", dest="pdbfile", help="pdbfile") parser.add_option("-s", dest="sele", help="sele") parser.add_option("-g", dest="grid", help="grid") parser.add_option("-o", dest="outfile", help="outfile") parser.add_option("-r", dest="replace", help="replace", action="store_true") parser.add_option("-e", dest="exclude", help="exclude", action="store_true") parser.add_option("-c", dest="cutoff", help="cutoff", default=3.0) (options, args) = parser.parse_args() if not options.pdbfile or not options.grid: parser.print_help() sys.exit() if options.outfile: outgrid = options.outfile elif options.replace: outgrid = options.grid else: parser.print_help() sys.exit() protein = Molecule() protein.readPDB(options.pdbfile) if options.sele: selection = Selection() selection.makeSelection(options.sele) newmol = selection.apply_selection(protein) else: newmol = protein.clone() mygrid = grid() mygrid.read(options.grid) atomlist = newmol.atomList() if options.exclude: gridTrimExclude(mygrid, atomlist, float(options.cutoff)) else: gridTrimInclude(mygrid, atomlist, float(options.cutoff)) mygrid.write(outgrid)
def testPickle(self): import pickle m = Molecule() file1 = '../proteins/alanin.psf' file2 = '../proteins/alanin.dcd' m.load(file1) m.load(file2) f = open('test.pkl', 'w') pickle.dump(m, f) f.close() g = open('test.pkl', 'r') m2 = pickle.load(g)
def main(): parser = OptionParser() parser.add_option("-p", dest="pdbfile", help="pdbfile") parser.add_option("-P", dest="pdblist", help="pdblist") parser.add_option("-o", dest="outfile", help="outfile") parser.add_option("-O", dest="outlist", help="outlist") parser.add_option("-r", dest="replace", help="replace", action="store_true") parser.add_option("-c", dest="chain", help="chain") parser.set_description(main.__doc__) (options, args) = parser.parse_args() pdbfiles = [] if options.pdblist: pdbfiles = files_from_list(options.pdblist) elif options.pdbfile: pdbfiles.append(options.pdbfile) else: parser.print_help() sys.exit() outfiles = [] if options.outlist: try: OUTLIST = open(outlist, 'r') except: print "unable to open file: ", outlist sys.exit() for line in OUTLIST.readlines(): line = string.strip(line) outfiles.append(line) elif options.outfile: outfiles.append(options.outfile) elif options.replace: for file in pdbfiles: outfiles.append(file) else: parser.print_help() sys.exit() if len(pdbfiles) != len(outfiles): print "number of pdbfiles and outfiles differ" sys.exit() if not options.chain: parser.print_help() sys.exit() protein = Molecule() for i in range(len(pdbfiles)): protein.readPDB(pdbfiles[i]) for chain in protein.chain: chain.name = options.chain protein.writePDB(outfiles[i]) protein.clear()
def extract_molecules_from_smiles(SMILES): size = len(SMILES) molecules = np.empty(size, dtype=object) # TODO: Change it back to batch_size for i in xrange(size): molecules[i] = Molecule.Molecule(SMILES[i]) return molecules
def p_central(p): '''B : ELEMENT ELEMENT NUMBER''' p[0] = (p[1], p[2], p[3]) bonds = 0 if (p[-1] == "-"): lbond = True else: lbond = False if (lbond): bonds += 1 bonds += p[3] central = p[1] bonded = p[2] mol = Molecule(central, bonded, bonds) # Se crea objeto Molecule y se enlaza a "chain" chain.append( mol ) # Esta lista se pasa a la clase Graph.py para que llame a los métodos de graficación if not (validateOctect(p[1], bonds)): raise ValueError("No se cumple con el octeto") if not (validateBondOctect(p[2])): raise ValueError("No se cumple con el octeto")
def runAll(mol, surface, molClass): resultPath(mol, molClass) au_a = 4.06 # Lattice constant of gold relative_coverage = 1.0 Density = 21.6 * relative_coverage # Angstroms^2/chain GOLD_Obj = Surface.Surface( data.getSurface(surface)) # Make gold "Surface Object" Mol_Obj = Molecule.Molecule(mol, data.getMol( mol, molClass)) # Make Molecular objects Mol_Obj.UnConverged = True Box_Length = GOLD_Obj.Box_Length Area = Box_Length[0] * Box_Length[1] Num_SAMs = int(np.sqrt(Area / Density)) Mol_Obj.Set_Up_FF(run_orca=True, local=True) # Parameterize Molecule Object OPLS.Assign_OPLS(Mol_Obj, ChelpG=False) # Parameterize Molecule Object OPLS.Assign_OPLS(GOLD_Obj, ChelpG=False) # Parametrize Au slab SAM_System = SAM.SAM(Mol_Obj, GOLD_Obj, Num_SAMs, Box_Length, mol) SAM_System.Gen_SAM() SAM_System.Write_LAMMPS_Data() SAM_System.Run_Lammps_Init() SAM_System.Run_Lammps_NPT(Temp_Out=400, time_steps=5000000) SAM_System.Run_Lammps_NPT(Temp_Out=400, time_steps=5000000) SAM_System.Run_Lammps_NPT(Temp_Out=300, time_steps=5000000) SAM_System.Run_Lammps_NPT(Temp_Out=300, time_steps=5000000) SAM_System.Run_Lammps_NPT(Temp_Out=300, time_steps=5000000) print "Aromodel.py complete for: " + mol + " molecule on " + surface + " surface!"
def testFiles(self): m = Molecule() file1 = '../proteins/alanin.psf' file2 = '../proteins/alanin.dcd' m.load(file1) m.load(file2) self.failUnless(m.files() is not [file1, file2]) self.failUnless(m.types() is not ['psf', 'dcd']) m.delete()
def read_molecules(self): files = glob.glob(Kegg.MOL_FOLDER + "*.mol") files = map(lambda fn: fn[fn.rfind("/"):-4], files) # take only short names for fn in files: m = Molecule(fn) self.molecules.append(m)
def main(): parser = OptionParser() parser.add_option("-p", dest="pdbfile", help="pdbfile") (options, args) = parser.parse_args() if not options.pdbfile: parser.print_help() sys.exit() mol = Molecule() mol.readPDB(options.pdbfile) for chain in mol.chain: for res in chain.residue: for atom in res.atom: print "|" + atom.name + "|" + atom.element
def tube_through_atoms(atoms, radius=0, band_length=0, segment_subdivisions=10, circle_subdivisions=15, follow_bonds=True, color=None, surface_model=None, model_id=None): if len(atoms) == 0: return None, [] if follow_bonds: chains = atom_chains(atoms) else: chains = [(atoms, None)] if color is None: color = (1, 1, 1, 1) s = surface_model sxf = (s or atoms[0].molecule).openState.xform plist = [] import Molecule as M for atoms, bonds in chains: xyz_path = M.atom_positions(atoms, sxf) point_colors = [M.atom_rgba(a) for a in atoms] if bonds is None: segment_colors = [color] * (len(atoms) - 1) else: segment_colors = [M.bond_rgba(b) for b in bonds] p = banded_tube(xyz_path, point_colors, segment_colors, radius, segment_subdivisions, circle_subdivisions, band_length, surface_model=s, model_id=model_id) if p: plist.append(p) s = p.model if s: s.openState.xform = sxf return s, plist
def main(): """ creates a posfile from a protein """ parser = OptionParser() parser.add_option("-p", dest="pdbfile", help="pdbfile") parser.add_option("-o", dest="outfile", help="outfile") parser.set_description(main.__doc__) (options, args) = parser.parse_args() if not options.pdbfile or not options.outfile: parser.print_help() sys.exit() try: OUTFILE = open(options.outfile, 'w') except: print "unable to create posfile" sys.exit() mol = Molecule() mol.readPDB(options.pdbfile) nres = mol.numResidues() for i in range(1, nres + 1): OUTFILE.write(str(i) + " ") OUTFILE.close() mol.clear()
def atoms_center_of_mass(atoms, cxf=None): import Molecule xyz = Molecule.atom_positions(atoms, cxf) from numpy import array, float32, dot weights = array([a.element.mass for a in atoms], float32) w = weights.sum() c = tuple(dot(weights, xyz) / w) return c
def testRepDuplication(self): m0a = Molecule(id=self.mol1.id) m0b = Molecule(id=self.mol1.id) reps = m0a.reps() test1 = lambda: m0a.addRep(reps[0]) test2 = lambda: m0b.addRep(reps[0]) self.failUnlessRaises(ValueError, test1) self.failUnlessRaises(ValueError, test2)
def main(): """ reads in a pdbfile and writes out the protein sequence """ parser = OptionParser() parser.add_option("-p", dest="pdbfile", help="pdbfile") parser.add_option("-P", dest="pdblist", help="pdblist") parser.add_option("-t", dest="transpose", help="transpose", action="store_true") parser.add_option("-n", dest="number", help="number", action="store_true") parser.add_option("-r", dest="range", help="range") parser.add_option("-s", dest="selection", help="selection") parser.set_description(main.__doc__) (options, args) = parser.parse_args() pdbfiles = [] if options.pdblist: pdbfiles = files_from_list(options.pdblist) elif options.pdbfile: pdbfiles.append(options.pdbfile) else: parser.print_help() sys.exit() if options.selection: sele = Selection() sele.makeSelection(options.selection) seq_min = 1 seq_max = 1 if options.range: (min, max) = string.split(arg, "-") seq_min = int(min) seq_max = int(max) protein = Molecule() Seq = "" for pdb in pdbfiles: protein.readPDB(pdb) if options.selection: newmol = sele.apply_selection(protein) Seq = newmol.sequence() else: Seq = protein.sequence() if options.range: Seq = Seq[seq_min:seq_max] if options.transpose: for i in range(len(Seq)): print Seq[i] else: print Seq protein.clear()
def load(self,infile,mode): files=[] self.logger.info("\n> Preparing molecules database...") f = open(infile, 'r+') for line in f: w=line.split() if len(w)==0: #to new line if line is empty continue if len(w)>0 and "#" in w[0]: #skip commented line continue if len(w[0])>1: raise IOError("found %s identifier in database file %s.\nOne letter code expected!"%(w[0],infile)) try: self.logger.info(">> loading PDB %s"%w[1]) m=Molecule() m.import_pdb(w[1],mode) except IOError: raise IOError("Could not load PDB file %s for molecule %s"%(w[1],w[0])) try: if mode=="gromacs": if len(w)==3: self.logger.info(">> loading topology %s"%w[2]) m.import_topology(w[2]) else: raise IOError("in gromacs mode, a topology file is expected for molecule %s!"%w[0]) except Exception, e: raise IOError("Could not load topology file %s for molecule %s!\n%s"%(w[2],w[0],e)) if w[0] in self.molecules.keys(): self.logger.warning("\n> WARNING: duplicate key %s in database %s. Overwriting."%(w[0], infile)) self.molecules[w[0]]=m
def testFiles(self): m=Molecule() file1='../proteins/alanin.psf' file2='../proteins/alanin.dcd' m.load(file1) m.load(file2) self.failUnless(m.files() is not [file1,file2]) self.failUnless(m.types() is not ['psf', 'dcd']) m.delete()
def main(): """ lists the chains that are in a given pdbfile """ parser = OptionParser() parser.add_option("-p", dest="pdbfile", help="pdbfile") parser.set_description(main.__doc__) (options, args) = parser.parse_args() if not options.pdbfile: parser.print_help() sys.exit() protein = Molecule() protein.readPDB(options.pdbfile) print options.pdbfile + ": " + str(protein.numChains()) for chain in protein.chain: print chain.name
def main(): """ prints the catalytic residues in the pdbfile """ parser = OptionParser() parser.add_option("-p", dest="pdbfile", help="pdbfile") parser.add_option("-P", dest="pdblist", help="pdblist") parser.add_option("-d", dest="dash", help="dash", action="store_true") parser.set_description(main.__doc__) (options, args) = parser.parse_args() pdbfiles = [] if options.pdblist: pdbfiles = files_from_list(options.pdblist) elif options.pdbfile: pdbfiles.append(options.pdbfile) else: parser.print_help() sys.exit() protein = Molecule() med = "" if options.dash: med = "-" for pdbfile in pdbfiles: protein.readPDB(pdbfile) cat = getCatalyticResidues(protein) print pdbfile, mystring = "" for c in cat: mystring += c.name + med + c.file_id.strip() + "_" print mystring protein.clear()
def load(self, infile, mode): files=[] self.logger.info("\n> Preparing molecules database...") try: f = open(infile, 'r+') except: raise IOError("database file %s not found!"%infile) #append folder of database file at the beginning of search path thisdir=os.path.dirname(os.path.abspath(infile)) os.environ["ASSEMBLEPATH"]="%s;%s"%(thisdir, os.environ["ASSEMBLEPATH"]) for line in f: w=line.split() if len(w)==0: #to new line if line is empty continue if len(w)>0 and "#" in w[0]: #skip commented line continue if len(w[0])>1: raise IOError("found %s identifier in database file %s.\nOne letter code expected!"%(w[0],infile)) fname=self.findfile(w[1]) if fname=="": raise IOError("PDB file %s not found for molecule %s"%(w[1],w[0])) try: self.logger.info(">> loading PDB %s"%fname) m=Molecule() m.import_pdb(fname, mode) except IOError: raise IOError("loading of PDB file %s failed for molecule %s"%(fname,w[0])) try: if mode=="gromacs": if len(w)==3: fname=self.findfile(w[2]) if fname=="": raise IOError("topology file %s not found for molecule %s"%(w[2],w[0])) self.logger.info(">> loading topology %s"%fname) m.import_topology(fname) else: raise IOError("in gromacs mode, a topology file is expected for molecule %s!"%w[0]) except Exception, e: raise IOError("Could not load topology file %s for molecule %s!\n%s"%(w[2],w[0],e)) if w[0] in self.molecules.keys(): self.logger.warning("\n> WARNING: duplicate key %s in database %s. Overwriting."%(w[0], infile)) self.molecules[w[0]]=m
def main(): Script, File_Name, N = sys.argv N = int(N) print File_Name Name = File_Name.split('.')[0] + "_%s" % N Solvent = Molecule.Molecule(File_Name) Solvent.UnConverged = True Solvent.Set_Up_FF(run_orca=True, local=False) OPLS.Assign_OPLS(Solvent, ChelpG=False) Solvent_System = System.System([Solvent], [N], 200.0, Name) Solvent_System.Gen_Rand() Solvent_System.Write_LAMMPS_Data() Solvent_System.Run_Lammps_Init()
def read_reactants(self): left = 50 max_right = 0 top = 50 max_bottom = 0 for i in range(len(self.subs)): m = Molecule(self.subs[i], self, left, top) self.subs[i] = m top = m.max_y + 50 if max_right < m.max_x: max_right = m.max_x if max_bottom < m.max_y: max_bottom = m.max_y left = max_right + 100 top = 50 for i in range(len(self.prods)): m = Molecule(self.prods[i], self, left, top) self.prods[i] = m top = m.max_y + 50 if max_right < m.max_x: max_right = m.max_x if max_bottom < m.max_y: max_bottom = m.max_y self.subs = [m for m in self.subs if m.graph and m.graph.atoms] # filter atomless molecules self.prods = [m for m in self.prods if m.graph and m.graph.atoms ] # filter atomless molecules # trimmed formula containing only non-empty molecules self.trim_formula = " + ".join([ m.ligand for m in self.subs ]) + " <=> " + " + ".join([m.ligand for m in self.prods]) self.height = max_bottom + 50 self.width = max_right + 50
def show_cube(cube_file, iso_value=0.002): """ loads cube file and displays the geometry and the volumetric data in the VMD main window """ mol = Molecule.Molecule() mol.load(cube_file) mol.rename(cube_file.replace(".cube", "")) mol.clearReps() # lines = Molecule.MoleculeRep(style="Lines", material="Opaque") mol.addRep(lines) # isosurface data for positive density iso_plus = Molecule.MoleculeRep(style="IsoSurface", material="Transparent") iso_plus.changeStyle("IsoSurface %f 0 0 0" % iso_value) iso_plus.changeColor("ColorID 0") mol.addRep(iso_plus) # negative density iso_minus = Molecule.MoleculeRep(style="IsoSurface", material="Transparent") iso_minus.changeStyle("IsoSurface %f 0 0 0" % (-iso_value)) iso_minus.changeColor("ColorID 1") mol.addRep(iso_minus) return mol
def get_partial_charges(molclass, mol): Mol = Molecule.Molecule(mol, DataFilesHandler.getMol(mol, molclass)) Mol.UnConverged = True Mol.Set_Up_FF(run_orca=False, molclass=molclass, mol=mol) Assign_OPLS(Mol, ChelpG=False) # Parameterize Molecule Object partial_charges = [] OPLS_Types = [] for Atom in Mol.Atom_List: if (Atom.OPLS_Type) in OPLS_Types: continue else: partial_charges.append((Atom.Element, Atom.Charge)) OPLS_Types.append(Atom.OPLS_Type) return partial_charges
def main(): """ changes MSE residues to MET that are found in crystal structures """ parser = OptionParser() parser.add_option("-p", dest="pdbfile", help="pdbfile") parser.add_option("-P", dest="pdblist", help="pdblist") parser.add_option("-o", dest="outfile", help="outfile") parser.add_option("-O", dest="outlist", help="outlist") parser.add_option("-r", dest="replace", help="replace", action="store_true") parser.set_description(main.__doc__) (options, args) = parser.parse_args() pdbfiles = [] if options.pdblist: pdbfiles = files_from_list(options.pdblist) elif options.pdbfile: pdbfiles.append(options.pdbfile) else: parser.print_help() sys.exit() outfiles = [] if options.outlist: outfiles = files_from_list(options.outlist) elif options.outfile: outfiles.append(options.outfile) elif options.replace: for file in pdbfiles: outfiles.append(file) else: parser.print_help() sys.exit() if len(pdbfiles) != len(outfiles): print "number of pdbfiles and outfiles differ" sys.exit() protein = Molecule() for i in range(len(pdbfiles)): protein.readPDB(pdbfiles[i]) fixMet(protein) protein.writePDB(outfiles[i]) protein.clear()
class MoleculeTestCase(unittest.TestCase): def setUp(self): self.mol1 = Molecule() self.mol1.load('../proteins/brH.pdb') def tearDown(self): self.mol1.delete() self.mol1 = None def testWebPDB(self): newmol=Molecule() newmol.load('1tit') self.failUnlessEqual(newmol.numFrames(), 1) newmol.delete() def testRename(self): newname = 'titin from rcsb' self.mol1.rename(newname) self.failUnlessEqual(self.mol1.name(), newname) def testBadID(self): thetest=lambda: Molecule(id=-5) self.failUnlessRaises(ValueError, thetest) def testBadFile(self): thetest=lambda: Molecule().load('/path/to/bogus/file','psf') self.failUnlessRaises(IOError, thetest) def testRepStr(self): for rep in self.mol1.reps(): print rep def testFiles(self): m=Molecule() file1='../proteins/alanin.psf' file2='../proteins/alanin.dcd' m.load(file1) m.load(file2) self.failUnless(m.files() is not [file1,file2]) self.failUnless(m.types() is not ['psf', 'dcd']) m.delete() def testPickle(self): import pickle m=Molecule() file1='../proteins/alanin.psf' file2='../proteins/alanin.dcd' m.load(file1) m.load(file2) f=open('test.pkl', 'w') pickle.dump(m, f) f.close() g=open('test.pkl', 'r') m2=pickle.load(g) def testFrame(self): self.mol1.load('../proteins/brH.pdb') self.mol1.load('../proteins/brH.pdb') self.mol1.load('../proteins/brH.pdb') self.failUnlessEqual(self.mol1.setFrame(2).curFrame(), 2) def testFrameRange(self): m=Molecule() m.load('../proteins/alanin.psf') m.load('../proteins/alanin.dcd', first=10, last=30, step=2, waitfor=-1) self.failUnlessEqual(m.numFrames(), 11) m.delete() def testDelFrame(self): m=Molecule() m.load('../proteins/alanin.psf') m.load('../proteins/alanin.dcd') m.delFrame(first=10, last=30, step=2) self.failUnlessEqual(m.numFrames(), 89) def testDupFrame(self): self.mol1.dupFrame(0).dupFrame(1).dupFrame() self.failUnlessEqual(self.mol1.numFrames(), 4) def testVolsets(self): self.mol1.load('/scratch/v46met_solved_2fofc.map',filetype='edm') def testRepCreateDestroy(self): bonds=MoleculeRep(style="Bonds") self.mol1.addRep(bonds) self.failUnlessEqual(self.mol1.numReps(), 2) self.mol1.delRep(bonds) self.failUnlessEqual(self.mol1.numReps(), 1) def testClearReps(self): self.mol1.addRep(MoleculeRep()) self.mol1.clearReps() self.failUnlessEqual(self.mol1.numReps(), 0) def testRepMod(self): self.mol1.clearReps() rep=MoleculeRep() self.mol1.addRep(rep) style="VDW" color="Index" sel="name CA" mat="Transparent" rep.changeStyle(style) rep.changeColor(color) rep.changeSelection(sel) rep.changeMaterial(mat) newrep=self.mol1.reps()[0] self.failUnlessEqual(newrep.style, style) self.failUnlessEqual(newrep.color, color) self.failUnlessEqual(newrep.selection, sel) self.failUnlessEqual(newrep.material, mat) def testRepAutoUpdate(self): for rep in self.mol1.reps(): self.failUnlessEqual(self.mol1.autoUpdate(rep), 0) self.mol1.autoUpdate(rep, 1) self.failUnlessEqual(self.mol1.autoUpdate(rep), 1) def testRepDuplication(self): m0a = Molecule(id=self.mol1.id) m0b = Molecule(id=self.mol1.id) reps=m0a.reps() test1=lambda: m0a.addRep(reps[0]) test2=lambda: m0b.addRep(reps[0]) self.failUnlessRaises(ValueError, test1) self.failUnlessRaises(ValueError, test2) def testSSRecalc(self): self.failUnless(self.mol1.ssRecalc())
def setUp(self): self.mol1 = Molecule() self.mol1.load('../proteins/brH.pdb')
def testWebPDB(self): newmol=Molecule() newmol.load('1tit') self.failUnlessEqual(newmol.numFrames(), 1) newmol.delete()
def testFrameRange(self): m=Molecule() m.load('../proteins/alanin.psf') m.load('../proteins/alanin.dcd', first=10, last=30, step=2, waitfor=-1) self.failUnlessEqual(m.numFrames(), 11) m.delete()
def testDelFrame(self): m=Molecule() m.load('../proteins/alanin.psf') m.load('../proteins/alanin.dcd') m.delFrame(first=10, last=30, step=2) self.failUnlessEqual(m.numFrames(), 89)