def cdfMol_pdb(pdb, output, name): initial_time = time.time() cdf_mol = Chem.BasicMolecule() pdb_mol = Chem.BasicMolecule() pdb_str = open(pdb, 'r').read().replace('WAT', 'HOH').replace('HIE', 'HIS') pdb_reader = Biomol.PDBMoleculeReader(Base.StringIOStream(pdb_str)) Biomol.setPDBApplyDictAtomBondingToNonStdResiduesParameter( pdb_reader, True) if not pdb_reader.read(pdb_mol): return None Chem.calcImplicitHydrogenCounts(pdb_mol, False) Chem.perceiveHybridizationStates(pdb_mol, False) Chem.setAtomSymbolsFromTypes(pdb_mol, False) Chem.perceiveSSSR(pdb_mol, False) Chem.setRingFlags(pdb_mol, False) Chem.setAromaticityFlags(pdb_mol, False) cdf_mol.assign(pdb_mol) for atom in cdf_mol.atoms: Chem.set3DCoordinatesArray(atom, Math.Vector3DArray()) i = 0 while i < cdf_mol.numAtoms: Chem.get3DCoordinatesArray(cdf_mol.getAtom(i)).addElement( Chem.get3DCoordinates(pdb_mol.getAtom(i))) i += 1 tmp_output = output + name + ".cdf" try: Chem.FileCDFMolecularGraphWriter(tmp_output).write(cdf_mol) except: print('> Cdf_mol writing failure.') raise residues = Biomol.ResidueList(cdf_mol) tmp_output = output + name + "_residue_info.txt" with open(tmp_output, 'w') as txt_writer: txt_writer.write('residue name_resid_chain\n') for res in residues: res_id = getResidueID(res) txt_writer.write('{}: \n'.format(res_id)) calc_time = time.time() - initial_time print('> Cdf and amino acid residue number list files generated in {}s'. format(int(calc_time)))
def mol_to_smiles(mol, kekulized=False, canonical=True, atom_stereo=True, hydrogen_deplete=True, bond_stereo=False): stream = Base.StringIOStream() w = Chem.SMILESMolecularGraphWriter(stream) Chem.setSMILESWriteKekuleFormParameter(w, kekulized) Chem.setSMILESWriteCanonicalFormParameter(w, canonical) Chem.setSMILESRecordFormatParameter(w, 'S') Chem.setSMILESWriteAtomStereoParameter(w, atom_stereo) Chem.setSMILESWriteBondStereoParameter(w, bond_stereo) Chem.setSMILESNoOrganicSubsetParameter(w, False) Chem.setOrdinaryHydrogenDepleteParameter(w, hydrogen_deplete) Chem.calcImplicitHydrogenCounts(mol, True) w.write(mol) w.close() return stream.value
def mol_from_smiles(smiles: str) -> Chem.BasicMolecule: ifs = Base.StringIOStream(smiles) mol = Chem.BasicMolecule() r = Chem.SMILESMoleculeReader(ifs) r.read(mol) return sanitize_mol(mol)
def readPDBFromString(string: str) -> Chem.BasicMolecule: s = Base.StringIOStream(string) protein = readPDBFromStream(s) return protein