def test_bad_init_parameterization(self): """ It checks that a call to the parameterize function with a Molecule unsuccessfully initialized raises an Exception. """ FORCEFIELD_NAME = 'openff_unconstrained-1.1.1.offxml' LIGAND_PATH = SET_OF_LIGAND_PATHS[0] ligand_path = get_data_file_path(LIGAND_PATH) molecule = Molecule() with pytest.raises(Exception): molecule.parameterize(FORCEFIELD_NAME) rdkit_toolkit = RDKitToolkitWrapper() molecule._rdkit_molecule = rdkit_toolkit.from_pdb(ligand_path) molecule._off_molecule = None with pytest.raises(Exception): molecule.parameterize(FORCEFIELD_NAME) openforcefield_toolkit = OpenForceFieldToolkitWrapper() molecule._off_molecule = openforcefield_toolkit.from_rdkit(molecule) molecule._rdkit_molecule = None with pytest.raises(Exception): molecule.parameterize(FORCEFIELD_NAME)
def _initialize_from_smiles(self, smiles): """ It initializes a molecule from a SMILES tag. Parameters ---------- smiles : str The SMILES tag to construct the molecule structure with """ self._initialize() print(' - Constructing molecule from a SMILES tag with RDKit') rdkit_toolkit = RDKitToolkitWrapper() self._rdkit_molecule = rdkit_toolkit.from_smiles(smiles) # TODO not sure if stereochemistry assignment from 3D is still necessary # RDKit must generate stereochemistry specifically from 3D coords # rdkit_toolkit.assign_stereochemistry_from_3D(self) # Set molecule name according to the SMILES tag if self.name == '': self.set_name(smiles) openforcefield_toolkit = OpenForceFieldToolkitWrapper() self._off_molecule = openforcefield_toolkit.from_rdkit(self)
def _initialize_from_smiles(self, smiles): """ It initializes a molecule from a SMILES tag. Parameters ---------- smiles : str The SMILES tag to construct the molecule structure with """ logger = Logger() logger.info(' - Initializing molecule from a SMILES tag') self._initialize() logger.info(' - Loading molecule from RDKit') rdkit_toolkit = RDKitToolkitWrapper() self._rdkit_molecule = rdkit_toolkit.from_smiles(smiles) # TODO not sure if stereochemistry assignment from 3D is still necessary # RDKit must generate stereochemistry specifically from 3D coords # rdkit_toolkit.assign_stereochemistry_from_3D(self) # Set molecule name according to the SMILES tag if self.name == '': logger.info(' - Setting molecule name to \'{}\''.format(smiles)) self.set_name(smiles) logger.info(' - Representing molecule with the Open Force Field ' + 'Toolkit') openforcefield_toolkit = OpenForceFieldToolkitWrapper() self._off_molecule = openforcefield_toolkit.from_rdkit(self)
def to_pdb_file(self, path): """ It writes the molecule to a PDB file. Parameters ---------- path : str Path to write to """ rdkit_toolkit = RDKitToolkitWrapper() rdkit_toolkit.to_pdb_file(self, path)
def set_conformer(self, conformer): """ It sets a new conformer to the molecule. Parameters ---------- conformer : an RDKit.Chem.rdchem.Conformer object The conformer to set to the molecule """ rdkit_toolkit = RDKitToolkitWrapper() rdkit_toolkit.set_conformer(self, conformer)
def get_pdb_atom_names(self): """ It returns the PDB atom names of all the atoms in the molecule. Returns ------- pdb_atom_names : str The PDB atom names of all the atoms in this Molecule object """ rdkit_toolkit = RDKitToolkitWrapper() return rdkit_toolkit.get_atom_names(self)
def _ipython_display_(self): """ It returns a RDKit molecule with an embeded 2D representation. Returns ------- representation_2D : a IPython display object It is displayable RDKit molecule with an embeded 2D representation """ from IPython.display import display rdkit_toolkit = RDKitToolkitWrapper() return display(rdkit_toolkit.get_2D_representation(self))
def _build_atoms(self): """It builds the atoms of the molecule.""" # PELE needs underscores instead of whitespaces pdb_atom_names = {(i, ): name.replace(' ', '_',) for i, name in enumerate(self.get_pdb_atom_names())} OPLS_types = {i: 'OFFT' for i in self.parameters.get_vdW_parameters().keys()} # TODO Which is the purpose of unknown value? Is it important? unknowns = {i: None for i in self.parameters.get_vdW_parameters().keys()} # TODO Create z-matrix from 3D coordinates coords = RDKitToolkitWrapper().get_coordinates(self) sigmas = self.parameters.get_vdW_sigmas() if all([sigma is None for sigma in sigmas.values()]): sigmas = self.parameters.get_vdW_sigmas_from_rmin_halves() epsilons = self.parameters.get_vdW_epsilons() # TODO Find a way to assign implicit solvent parameters to atoms with OFF born_radii = {i: None for i in self.parameters.get_vdW_parameters().keys()} # TODO Doublecheck later this relation SASA_radii = {i: j / 2.0 for i, j in sigmas.items()} # TODO Find a way to assign implicit solvent parameters to atoms with OFF nonpolar_gammas = {i: None for i in self.parameters.get_vdW_parameters().keys()} nonpolar_alphas = {i: None for i in self.parameters.get_vdW_parameters().keys()} for index in self.parameters.get_vdW_parameters().keys(): assert len(index) == 1, 'Index should be a tupple of length 1' atom = Atom(index=int(index[0]), PDB_name=pdb_atom_names[index], OPLS_type=OPLS_types[index], unknown=unknowns[index], x=coords[index][0], y=coords[index][1], z=coords[index][2], sigma=sigmas[index], epsilon=epsilons[index], charge=self.off_molecule.partial_charges[index], born_radius=born_radii[index], SASA_radius=SASA_radii[index], nonpolar_gamma=nonpolar_gammas[index], nonpolar_alpha=nonpolar_alphas[index]) self._add_atom(atom)
def _initialize_from_pdb(self, path): """ It initializes a molecule with the molecule structure read from a PDB file. Parameters ---------- path : str The path to a PDB with the molecule structure """ self._initialize() print(' - Loading molecule from RDKit') rdkit_toolkit = RDKitToolkitWrapper() self._rdkit_molecule = rdkit_toolkit.from_pdb(path) # RDKit must generate stereochemistry specifically from 3D coords rdkit_toolkit.assign_stereochemistry_from_3D(self) # Set molecule name according to PDB name if self.name == '': from pathlib import Path name = Path(path).stem self.set_name(name) # Set molecule tag according to PDB's residue name if self.tag == 'UNK': tag = rdkit_toolkit.get_residue_name(self) self.set_tag(tag) openforcefield_toolkit = OpenForceFieldToolkitWrapper() self._off_molecule = openforcefield_toolkit.from_rdkit(self)
def _initialize_from_pdb(self, path): """ It initializes a molecule with the molecule structure read from a PDB file. Parameters ---------- path : str The path to a PDB with the molecule structure """ logger = Logger() logger.info(' - Initializing molecule from PDB') self._initialize() logger.info(' - Loading molecule from RDKit') rdkit_toolkit = RDKitToolkitWrapper() self._rdkit_molecule = rdkit_toolkit.from_pdb(path) # Use RDKit template, if any, to assign the connectivity to # the current Molecule object if self.connectivity_template is not None: logger.info(' - Assigning connectivity from template') rdkit_toolkit.assign_connectivity_from_template(self) # RDKit must generate stereochemistry specifically from 3D coords logger.info(' - Assigning stereochemistry from 3D coordinates') rdkit_toolkit.assign_stereochemistry_from_3D(self) # Set molecule name according to PDB name if self.name == '': from pathlib import Path name = Path(path).stem logger.info(' - Setting molecule name to \'{}\''.format(name)) self.set_name(name) # Set molecule tag according to PDB's residue name if self.tag == 'UNK': tag = rdkit_toolkit.get_residue_name(self) logger.info(' - Setting molecule tag to \'{}\''.format(tag)) self.set_tag(tag) logger.info(' - Representing molecule with the Open Force Field ' + 'Toolkit') openforcefield_toolkit = OpenForceFieldToolkitWrapper() self._off_molecule = openforcefield_toolkit.from_rdkit(self)