def find_species_by_smiles(rmg_spc: list, smiles: str) -> Molecule: """ for list of rmg species find species by smiles :param rmg_spc: list of rmg species list :param smiles: (str) species as smiles :return: rmg species """ sp1 = Molecule().from_smiles(smiles) display(sp1) mol = None res = sp1.generate_resonance_structures() for i, x in enumerate(rmg_spc): for s in res: if x.is_isomorphic(s): print(x.molecule) print(x.thermo.comment) mol = x if mol is None: print("couldn't find the species") else: return mol
def __init__(self, smiles=[], rmg_species=None): """ A class that holds information for Species object """ assert isinstance(smiles, list) self._conformers = None if ((len(smiles) != 0) and rmg_species): # Provide both a list of smiles and an rmg_species assert isinstance( rmg_species, (rmgpy.molecule.Molecule, rmgpy.species.Species)) if isinstance(rmg_species, rmgpy.molecule.Molecule): rmg_species = RMGSpecies(molecule=[rmg_species]) try: rmg_species.generate_resonance_structures() except: logging.info( "Could not generate resonance structures for this species... Using molecule provided") else: try: rmg_species.generate_resonance_structures() except: logging.info( "Could not generate resonance structures for this species... Using molecule provided") smiles_list = [] for rmg_mol in rmg_species.molecule: smiles_list.append(rmg_mol.toSMILES()) for s in smiles_list: if s in smiles: continue if not(s in smiles): smiles.append(s) assert len(smiles) == len( smiles_list), "The list of smiles presented does not match the possible species provided" self.smiles = smiles self.rmg_species = rmg_species elif (rmg_species and (len(smiles) == 0)): # RMG species provided, but not smiles assert isinstance( rmg_species, (rmgpy.molecule.Molecule, rmgpy.species.Species)) if isinstance(rmg_species, rmgpy.molecule.Molecule): rmg_species = RMGSpecies(molecule=[rmg_species]) try: rmg_species.generate_resonance_structures() except: logging.info( "Could not generate resonance structures for this species... Using molecule provided") else: try: rmg_species.generate_resonance_structures() except: logging.info( "Could not generate resonance structures for this species... Using molecule provided") smiles = [] for rmg_mol in rmg_species.molecule: smiles.append(rmg_mol.toSMILES()) self.smiles = smiles self.rmg_species = rmg_species elif ((not rmg_species) and (len(smiles) != 0)): # smiles provided but not species species_list = [] for smile in smiles: molecule = RMGMolecule(SMILES=smile) species_list.append(molecule.generate_resonance_structures()) if len(smiles) != 1: got_one = False for s1 in species_list: for s2 in species_list: for m1 in s1: for m2 in s2: if m1.isIsomorphic(m2): got_one = True assert got_one, "SMILESs provided describe different species" smiles_list = [] for mol in species_list[0]: smiles_list.append(mol.toSMILES()) self.smiles = smiles_list self.rmg_species = species_list[0] else: self.smiles = [] self.rmg_species = rmg_species