def sanitize_smiles_molvs(smiles, largest_fragment=False): """Sanitize a SMILES with MolVS Parameters ---------- smiles : str SMILES string for a molecule. largest_fragment : bool Whether to select only the largest covalent unit in a molecule with multiple fragments. Default to False. Returns ------- str SMILES string for the sanitized molecule. """ standardizer = Standardizer() standardizer.prefer_organic = True mol = Chem.MolFromSmiles(smiles) if mol is None: return smiles try: mol = standardizer.standardize( mol) # standardize functional group reps if largest_fragment: mol = standardizer.largest_fragment( mol) # remove product counterions/salts/etc. mol = standardizer.uncharge(mol) # neutralize, e.g., carboxylic acids except Exception: pass return Chem.MolToSmiles(mol)
opts,args = parser.parse_args() fpred = open(opts.pred_path) fgold = open(opts.gold_path) feval = open(opts.pred_path + '.eval_by_smiles', 'w') print('## Bond types in output files are doubles? {}'.format(opts.bonds_as_doubles)) idxfunc = lambda a: a.GetAtomMapNum() bond_types = [Chem.rdchem.BondType.SINGLE, Chem.rdchem.BondType.DOUBLE, Chem.rdchem.BondType.TRIPLE, Chem.rdchem.BondType.AROMATIC] bond_types_as_double = {0.0: 0, 1.0: 1, 2.0: 2, 3.0: 3, 1.5: 4} from molvs import Standardizer standardizer = Standardizer() standardizer.prefer_organic = True def sanitize_smiles(smi, largest_fragment=False): mol = Chem.MolFromSmiles(smi) if mol is None: return smi try: mol = standardizer.standardize(mol) # standardize functional group reps if largest_fragment: mol = standardizer.largest_fragment(mol) # remove product counterions/salts/etc. mol = standardizer.uncharge(mol) # neutralize, e.g., carboxylic acids except Exception: pass return Chem.MolToSmiles(mol) try: