def testCifMissing(self): N = 7 cmd.fragment('gly', 'm1') cmd.alter('all', '(chain, segi, resv, alt) = ("?", ".", 5, "")') s = cmd.get_str('cif') self.assertTrue("'?'" in s or '"?"' in s) # chain self.assertTrue("'.'" in s or '"."' in s) # segi self.assertTrue(' ? ' in s) # e.g. pdbx_PDB_ins_code self.assertTrue(' . ' in s) # e.g. label_alt_id cmd.delete('*') cmd.set('cif_keepinmemory') cmd.load(s, 'm2', format='cifstr') self.assertEqual(['?'], cmd.get_chains()) self.assertEqual(cmd.count_atoms('segi .'), N) self.assertEqual(cmd.count_atoms('alt ""'), N) # no alt self.assertEqual(cmd.count_atoms('resi 5'), N) # no ins_code from pymol.querying import cif_get_array self.assertEqual(cif_get_array("m2", "_atom_site.type_symbol"), list('NCCOHHH')) self.assertEqual(cif_get_array("m2", "_atom_site.id", "i"), list(range(1, N + 1))) self.assertEqual(cif_get_array("m2", "_atom_site.auth_asym_id"), ['?'] * N) self.assertEqual(cif_get_array("m2", "_atom_site.label_asym_id"), ['.'] * N) self.assertEqual(cif_get_array("m2", "_atom_site.pdbx_pdb_ins_code"), [None] * N) self.assertEqual(cif_get_array("m2", "_atom_site.label_alt_id"), [None] * N)
def minimize(selection='all', forcefield='MMFF94s', method='Conjugate Gradients', nsteps0=500, conv=0.0001, cutoff=False, cut_vdw=6.0, cut_elec=8.0): mol_string = cmd.get_str('mol', selection) name = cmd.get_legal_name(selection) obconversion = ob.OBConversion() obconversion.SetInAndOutFormats('mol', 'mol') mol = ob.OBMol() obconversion.ReadString(mol, mol_string) ff = ob.OBForceField.FindForceField( forcefield) ## GAFF, MMFF94s, MMFF94, UFF, Ghemical ff.Setup(mol) if cutoff == True: ff.EnableCutOff(True) ff.SetVDWCutOff(cut_vdw) ff.SetElectrostaticCutOff(cut_elec) if method == 'Conjugate Gradients': ff.ConjugateGradients(nsteps0, conv) else: ff.SteepestDescent(nsteps0, conv) ff.GetCoordinates(mol) nrg = ff.Energy() mol_string = obconversion.WriteString(mol) cmd.delete(name) if name == 'all': name = 'all_' cmd.read_molstr(mol_string, name, state=0, finish=1, discrete=1) print('#########################################') print('The Energy of %s is %8.2f %s ' % (name, nrg, ff.GetUnit())) print('#########################################')
def get_molstr(sele, state): '''Export the given selection to a molfile string''' try: # new in PyMOL 1.8.4 return cmd.get_str('mol', sele, state) except Exception as e: print(e) from chempy import io model = cmd.get_model(sele, state) for a in model.atom: a.symbol = a.symbol.capitalize() return ''.join(io.mol.toList(model))
def conf_search(selection='all', forcefield='MMFF94s', method='Weighted', nsteps1=500, conformers=25, lowest_conf=5): mol_string = cmd.get_str('mol', selection) name = cmd.get_legal_name(selection) obconversion = ob.OBConversion() obconversion.SetInAndOutFormats('mol', 'mol') mol = ob.OBMol() obconversion.ReadString(mol, mol_string) ff = ob.OBForceField.FindForceField( forcefield) ## GAFF, MMFF94s, MMFF94, UFF, Ghemical ff.Setup(mol) if method == 'Weighted': ff.WeightedRotorSearch(conformers, nsteps1) elif method == 'Random': ff.RandomRotorSearch(conformers, nsteps1) else: ff.SystematicRotorSearch(nsteps1) if name == 'all': name = 'all_' if method in ['Weighted', 'Random']: ff.GetConformers(mol) print('##############################################') print(' Conformer | Energy | RMSD') nrg_unit = ff.GetUnit() rmsd = 0 ff.GetCoordinates(mol) nrg = ff.Energy() conf_list = [] for i in range(conformers): mol.SetConformer(i) ff.Setup(mol) nrg = ff.Energy() conf_list.append((nrg, i)) conf_list.sort() lenght_conf_list = len(conf_list) if lowest_conf > lenght_conf_list: lowest_conf = lenght_conf_list for i in range(lowest_conf): nrg, orden = conf_list[i] name_n = '%s%02d' % (name, i) cmd.delete(name_n) mol.SetConformer(orden) mol_string = obconversion.WriteString(mol) cmd.read_molstr(mol_string, name_n, state=0, finish=1, discrete=1) if i != 0: rmsd = cmd.fit(name_n, '%s00' % name, quiet=1) print('%15s | %10.2f%9s |%6.1f' % (name_n, nrg, nrg_unit, rmsd)) print('##############################################') else: ff.GetCoordinates(mol) nrg = ff.Energy() mol_string = obconversion.WriteString(mol) cmd.delete(name) cmd.read_molstr(mol_string, name, state=0, finish=1, discrete=1) print('#########################################') print('The Energy of %s is %8.2f %s ' % (name, nrg, ff.GetUnit())) print('#########################################')