def add_with_rdkit(self, filename, filetype, strict=False, **kwargs): """Add molecule using rdkit""" with open(filename, "r") as inputfile: text = inputfile.read() if filetype == "auto": filetype = os.path.splitext(filename)[1] if filetype == "inchi": rdmol = Chem.MolFromInchi(text) elif filetype == "mol2": rdmol = Chem.MolFromMol2File(filename) elif filetype == "mol": rdmol = Chem.MolFromMolFile(filename) elif filetype == "pdb": rdmol = Chem.MolFromPdbFile(filename) elif filetype in ["smi", "smiles"]: rdmol = Chem.MolFromSmiles(text) elif filetype == "tpl": rdmol = Chem.MolFromTPLFile(filename) elif filetype == "smarts": if strict: raise IOError("Smarts is pattern, smiles for molecules.") else: print "WARNING: Use smiles, ignoring smarts." % filetype return else: if strict: raise IOError("Filetype (%s) not in rdkit." % filetype) else: print "WARNING: Could not filetype %s." % filetype return rdmol = Chem.addHs(rdmol) self.molstr.append(Chem.MolToPDBBlock)