def getParameters(self): import tempfile if not self.completed: raise ValueError("Parameterisation is not complete") # look for the right files in the output directory dir = os.path.join(self.directory, "999-results") rtf = os.path.join(dir, "mol.rtf") prm = os.path.join(dir, "mol.prm") xyz = os.path.join(dir, "mol.xyz") pdb = os.path.join(dir, "mol.pdb") rtf_tmp = tempfile.mkstemp(suffix=".rtf") prm_tmp = tempfile.mkstemp(suffix=".prm") pdb_tmp = tempfile.mkstemp(suffix=".pdb") xyz_tmp = tempfile.mkstemp(suffix=".xyz") os.close(rtf_tmp[0]) os.close(prm_tmp[0]) os.close(pdb_tmp[0]) os.close(xyz_tmp[0]) shutil.copyfile(rtf, rtf_tmp[1]) shutil.copyfile(prm, prm_tmp[1]) shutil.copyfile(xyz, xyz_tmp[1]) # The Output minimised structure is in XYZ format # Need to turn it into a PDB with correct atom naming mol = Molecule(xyz) Parameterisation._rename_mol(mol) # Canonicalise atom and reside naming mol.write(pdb_tmp[1]) return { "RTF": rtf_tmp[1], "PRM": prm_tmp[1], "PDB": pdb_tmp[1] }
def listDihedrals(filename): # This routine gets the names of the atoms in the soft dihedrals # It's so horrible, since we have to jump through hoops to # set up the input for gen_soft_list ll1 = [] ll2 = [] env = Parameterisation._preflight_test(None) mol = Molecule(filename); mol = Parameterisation._rename_mol(mol) mol.bonds = mol._guessBonds() # make a tempdir with tempfile.TemporaryDirectory() as td: # td=tempfile.mkdtemp() # print(td) pwd = os.getcwd() os.chdir(td) f = open("mol.prm", "w") f.close() mol.write("mol.pdb") mol.write("mol-opt.xyz") mol.write("mol.xpsf", type="psf") for charge in range(-1, 2): ret = subprocess.check_output( [env['BIN_MATCH'], "-charge", str(charge), "-forcefield", "top_all36_cgenff_new", "mol.pdb"], stderr=subprocess.STDOUT, shell=False, stdin=None) ret = subprocess.check_output([env['BIN_GEN_XPSF'], "mol.rtf", "mol.xpsf", "MOL"], stderr=subprocess.STDOUT, shell=False, stdin=None) ret = subprocess.check_output([env['BIN_GEN_SOFT_LIST']], stderr=subprocess.STDOUT, shell=False, stdin=None) f = open("soft-dih-list.txt", "r") ff = f.readlines() for l in ff: ss = [] tt = [] for m in l.split(): tt.append(int(m)) ss.append(mol.name[int(m) - 1].strip().upper()) ll1.append(tt) ll2.append(ss) f.close() os.chdir(pwd) return (ll1, ll2)
def renameStructure(filename): m = Molecule(filename) m = Parameterisation._rename_mol(m) m.write(filename)