def test_MDL_aromaticity(verbose=False): """Test support for alternate aromaticity models.""" ffxml = StringIO(ffxml_MDL_contents) ff = ForceField(ffxml) from openeye import oechem mol = oechem.OEMol() oechem.OEParseSmiles(mol, 'c12c(cccc1)occ2') oechem.OEAddExplicitHydrogens(mol) labels = ff.labelMolecules([mol], verbose=True) # The bond 6-7 should get the b16 parameter iff the MDL model is working, otherwise it will pick up just the generic details = labels[0]['HarmonicBondGenerator'] found = False for (atom_indices, pid, smirks) in details: if pid == 'b16' and atom_indices == [6, 7]: found = True if not found: raise Exception("Didn't find right param.")
def test_molecule_labeling(verbose = False): """Test using labelMolecules to see which parameters applied to an oemol.""" from openeye import oechem mol = oechem.OEMol() oechem.OEParseSmiles(mol, 'CCC') oechem.OEAddExplicitHydrogens(mol) ff = ForceField(get_data_filename('forcefield/Frosst_AlkEtOH.ffxml')) labels = ff.labelMolecules( [mol], verbose = verbose) # Check that force terms aren't empty print(labels[0].keys()) if not 'HarmonicBondGenerator' in labels[0].keys(): raise Exception("No force term assigned for harmonic bonds.") if not 'HarmonicAngleGenerator' in labels[0].keys(): raise Exception("No force term assigned for harmonic angles.") if not 'PeriodicTorsionGenerator' in labels[0].keys(): raise Exception("No force term assigned for periodic torsions.") if not 'NonbondedGenerator' in labels[0].keys(): raise Exception("No nonbonded force term assigned.")
def test_molecule_labeling(verbose=False): """Test using labelMolecules to see which parameters applied to an oemol.""" from openeye import oechem mol = oechem.OEMol() oechem.OEParseSmiles(mol, 'CCC') oechem.OEAddExplicitHydrogens(mol) ff = ForceField(get_data_filename('forcefield/Frosst_AlkEtOH.ffxml')) labels = ff.labelMolecules([mol], verbose=verbose) # Check that force terms aren't empty print(labels[0].keys()) if not 'HarmonicBondGenerator' in labels[0].keys(): raise Exception("No force term assigned for harmonic bonds.") if not 'HarmonicAngleGenerator' in labels[0].keys(): raise Exception("No force term assigned for harmonic angles.") if not 'PeriodicTorsionGenerator' in labels[0].keys(): raise Exception("No force term assigned for periodic torsions.") if not 'NonbondedGenerator' in labels[0].keys(): raise Exception("No nonbonded force term assigned.")
def get_molecule_parameterIDs( oemols, ffxml): """Process a list of oemols with a specified SMIRFF ffxml file and determine which parameters are used by which molecules, returning collated results. Parameters ---------- oemols : list List of OpenEye OEChem molecules to parse; must have explicit hydrogens. Returns ------- parameters_by_molecule : dict Parameter IDs used in each molecule, keyed by isomeric SMILES generated from provided OEMols. Each entry in the dict is a list which does not necessarily have unique entries; i.e. parameter IDs which are used more than once will occur multiple times. parameters_by_ID : dict Molecules in which each parameter ID occur, keyed by parameter ID. Each entry in the dict is a set of isomeric SMILES for molecules in which that parameter occurs. No frequency information is stored. """ # Create storage parameters_by_molecule = {} parameters_by_ID = {} # Generate isomeric SMILES isosmiles = list() for mol in oemols: smi = oechem.OECreateIsoSmiString(mol) if not smi in isosmiles: isosmiles.append(smi) # If the molecule is already here, raise exception else: raise ValueError("Error: get_molecule_parameterIDs has been provided a list of oemols which contains the same molecule, having isomeric smiles %s, more than once." % smi ) # Label molecules ff = ForceField( ffxml ) labels = ff.labelMolecules( oemols ) # Organize labels into output dictionary by looping over all molecules/smiles for idx in range(len(isosmiles)): # Pull smiles, initialize storage smi = isosmiles[idx] parameters_by_molecule[smi] = [] # Organize data for this molecule data = labels[idx] for force_type in data.keys(): for (atom_indices, pid, smirks) in data[force_type]: # Store pid to molecule parameters_by_molecule[smi].append(pid) # Store which molecule this pid occurred in if pid not in parameters_by_ID: parameters_by_ID[pid] = set() parameters_by_ID[pid].add(smi) else: parameters_by_ID[pid].add(smi) return parameters_by_molecule, parameters_by_ID
def get_molecule_parameterIDs(oemols, ffxml): """Process a list of oemols with a specified SMIRFF ffxml file and determine which parameters are used by which molecules, returning collated results. Parameters ---------- oemols : list List of OpenEye OEChem molecules to parse; must have explicit hydrogens. Returns ------- parameters_by_molecule : dict Parameter IDs used in each molecule, keyed by isomeric SMILES generated from provided OEMols. Each entry in the dict is a list which does not necessarily have unique entries; i.e. parameter IDs which are used more than once will occur multiple times. parameters_by_ID : dict Molecules in which each parameter ID occur, keyed by parameter ID. Each entry in the dict is a set of isomeric SMILES for molecules in which that parameter occurs. No frequency information is stored. """ # Create storage parameters_by_molecule = {} parameters_by_ID = {} # Generate isomeric SMILES isosmiles = list() for mol in oemols: smi = oechem.OECreateIsoSmiString(mol) if not smi in isosmiles: isosmiles.append(smi) # If the molecule is already here, raise exception else: raise ValueError( "Error: get_molecule_parameterIDs has been provided a list of oemols which contains the same molecule, having isomeric smiles %s, more than once." % smi) # Label molecules ff = ForceField(ffxml) labels = ff.labelMolecules(oemols) # Organize labels into output dictionary by looping over all molecules/smiles for idx in range(len(isosmiles)): # Pull smiles, initialize storage smi = isosmiles[idx] parameters_by_molecule[smi] = [] # Organize data for this molecule data = labels[idx] for force_type in data.keys(): for (atom_indices, pid, smirks) in data[force_type]: # Store pid to molecule parameters_by_molecule[smi].append(pid) # Store which molecule this pid occurred in if pid not in parameters_by_ID: parameters_by_ID[pid] = set() parameters_by_ID[pid].add(smi) else: parameters_by_ID[pid].add(smi) return parameters_by_molecule, parameters_by_ID