def mset_to_smiles(max_atoms, filename): mset = MSet() try: mset.load(filename) except json.JSONDecodeError: print("json decode error") return (None, None) if mset.n_atoms > max_atoms: return (None, None) geom = mset.get_min_geom try: charges = [ float(atom.labels['wB97X-D.6-311g**.charges']) for atom in geom.atoms ] except KeyError: charges = [ float(atom.labels['wb97x-d.6-311gss.mulliken_charges']) for atom in geom.atoms ] charge = sum(charges) / len(charges) try: mol = xyz2mol(geom.at_nums, [atom.xyz for atom in geom.atoms], charge) except Chem.AtomValenceException: print("atom valence exception") return (None, None) smiles = Chem.MolToSmiles(mol, isomericSmiles=False) m = Chem.MolFromSmiles(smiles) smiles = Chem.MolToSmiles(m, isomericSmiles=False) mset.identifiers.update({"smiles": smiles}) mset.save(filename) return (filename, smiles)
def mset_to_smiles(filename): mset = MSet() try: mset.load(filename) except json.JSONDecodeError: print("json decode error") return None geom = get_min_geom(mset.geometries) charge = 0 try: smiles = geom_to_smiles(geom, charge) except: return None mset.identifiers.update({"smiles": smiles}) mset.save(filename) return filename
def mset_to_smiles(filename): mset = MSet() mset.load(filename) geom = mset.get_min_geom try: cm5_charges = [ float(atom.labels['wb97x_dz.cm5_charges']) for atom in geom.atoms ] hirshfeld_charges = [ float(atom.labels['wb97x_dz.hirshfeld_charges']) for atom in geom.atoms ] charge = ((sum(cm5_charges) / len(cm5_charges)) + (sum(hirshfeld_charges) / len(hirshfeld_charges))) / 2 except: charge = 0 try: smiles = geom_to_smiles(geom, charge) except: return None mset.identifiers.update({"smiles": smiles}) mset.save(filename) return filename
else: opt_natoms[len(opt_mol_data['atoms'])] = [opt_mol] with open( "/mnt/sdb1/jeherr/chemspider_data/chno_msets/chno_opt_natoms.txt", "w") as f: json.dump(opt_natoms, f) opt_matches = {} meta_matches = {} for n_atoms, meta_mols in meta_natoms.items(): opt_mols = opt_natoms[n_atoms] opt_msets = [] meta_msets = [] for opt_mol in opt_mols: opt_mset = MoleculeSet() opt_mset.load(opt_mol) opt_mset.filename = opt_mol opt_msets.append(opt_mset) for meta_mol in meta_mols: meta_mset = MoleculeSet() meta_mset.load(meta_mol) meta_mset.filename = meta_mol meta_msets.append(meta_mset) for meta_mset in meta_msets: matches = [] for opt_mset in opt_msets: if meta_mset.compare_hash(opt_mset): matches.append(opt_mset.filename) meta_matches[meta_mset.filename] = matches for opt_mset in opt_msets: matches = []