def string(self, val): if not _os.path.exists(val): self._molecule = _rdkit.openAsRdkit(val, minimise=self.minimise) self._string = _rdmolfiles.MolToSmiles(self._molecule) else: raise ValueError( "Need a SMILES or InChI string instead of a filename")
def protonated_filename(self, val): with self.workdir: if val is None: self._protonated_filename = None self._protonated = False else: self._protonated_filename = _fileio.checkFileExists(val) self._molecule = _rdkit.openAsRdkit(self._protonated_filename, removeHs=False, minimise=self.minimise) self._string = _rdmolfiles.MolToSmiles(self.molecule) self._protonated = True
def __init__(self, input, parametrised_files=None, name=None, protonated=False, minimise=None, workdir="."): self.name = name self.workdir = _fileio.Dir(workdir) self.minimise = minimise # always set protonated to False and if a valid protonated file is given it is automatically set to True self.protonated_filename = None with self.workdir: if parametrised_files: self.molecule = _rdkit.openAsRdkit(parametrised_files, removeHs=False, minimise=False, template=input) self.protonated_filename = _rdkit.saveFromRdkit( self.molecule, "{}.pdb".format(name)) elif isinstance(input, str): if _os.path.exists(input): if protonated: self.protonated_filename = input else: self.molecule = _rdkit.openAsRdkit(input, minimise=minimise) else: self.string = input elif isinstance(input, _rdchem.Mol): self.molecule = input else: raise TypeError( "Need a SMILES, InChI string, filename or an RDKit object as an input" ) self.parametrised_files = parametrised_files self.minimise = False
def amberWrapper(params, filename, molecule_type, id=None, charge=None, *args, **kwargs): """ Parametrises an input file according to AMBER force field. Parameters ---------- params : ProtoCaller.Parametrise.Params Force field parameters. filename : str Name of the input file. molecule_type : str The type of the molecule. One of: "protein", "ligand", "cofactor", "water", "simple_anion", "complex_anion", "simple_cation", "complex_cation". id : str The name of the molecule. Default: equal to molecule_type. charge : bool The net charge of the molecule. Default: automatic detection by antechamber. args Positional arguments to be passed to the relevant wrapper. kwargs Keyword arguments to be passed to the relevant wrapper. Returns ------- files : [str] The output parametrised file(s). If there is more than one file, the first one is always the topology file and the second one - the coordinate file. """ if id is None: id = molecule_type force_fields, files, param_files = [], [filename], [] if molecule_type == "protein": force_fields = [params.protein_ff, params.water_ff] elif molecule_type in ["water", "simple_anion", "simple_cation"]: force_fields = [params.water_ff] elif molecule_type == "complex_anion": _warnings.warn( "AMBER parametrisation failed: polyatomic anions not supported") return elif molecule_type == "complex_cation": _warnings.warn( "AMBER parametrisation failed: transition metals not supported") return elif molecule_type == "cofactor": if params.water_ff != "tip3p" or params.protein_ff != "ff99SB": _warnings.warn("All cofactors have been parametrised for use with " "the ff99SB protein force field and the TIP3P " "water model. Be careful when using these " "parameters with %s" % params.water_ff.upper()) files = [] force_fields = [params.protein_ff, params.ligand_ff] param_files = _glob.glob("%s/shared/amber-parameters/cofactors/%s.*" % (_PC.HOMEDIR, id)) # here we override the default parametrisation behaviour for cofactors parametrised_files = runTleap(force_fields=force_fields, files=files, param_files=param_files, id=id, *args, **kwargs) filebase = _os.path.splitext(filename)[0] topol = "{}.prmtop".format(filebase) _os.rename(parametrised_files[0], topol) parametrised_files[0] = topol # convert the parametrised file into PDB and load in RDKit ref = _rdkit.openAsRdkit(filename, removeHs=False) mol = _pmd.openFilesAsParmed(parametrised_files) pdb_file = _pmd.saveFilesFromParmed(mol, [filename], overwrite=True)[0] mol = _rdkit.openAsRdkit(pdb_file, removeHs=False) # align the parametrised file to the molecule and overwrite # previous coordinates mol, mcs = _stdio.stdout_stderr()(_rdkit.alignTwoMolecules) \ (ref, mol, two_way_matching=True, mcs_parameters=dict(atomCompare="elements")) if min(mol.GetNumAtoms(), ref.GetNumAtoms()) != len(mcs): _warnings.warn("The cofactor {} does not perfectly match the " "AMBER parameter file. Please check your " "molecule.".format(id)) _os.remove(parametrised_files[1]) coord = "{}.inpcrd".format(filebase) parametrised_files[1] = _rdkit.saveFromRdkit(mol, coord) return parametrised_files elif molecule_type == "ligand": force_fields = [params.ligand_ff] files = [runAntechamber(params.ligand_ff, filename, charge=charge)] param_files = [runParmchk(params.ligand_ff, files[0])] else: raise ValueError("Value %s for molecule_type not supported " % molecule_type) return runTleap(force_fields=force_fields, files=files, param_files=param_files, id=id, *args, **kwargs)