本文整理汇总了Python中rdkit.Chem.MolToSmiles方法的典型用法代码示例。如果您正苦于以下问题:Python Chem.MolToSmiles方法的具体用法?Python Chem.MolToSmiles怎么用?Python Chem.MolToSmiles使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rdkit.Chem
的用法示例。
在下文中一共展示了Chem.MolToSmiles方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __getitem__
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import MolToSmiles [as 别名]
def __getitem__(self, idx):
mol = Chem.MolFromSmiles(self.batches[idx])
leaves = get_leaves(mol)
smiles_list = set( [Chem.MolToSmiles(mol, rootedAtAtom=i, isomericSmiles=False) for i in leaves] )
smiles_list = sorted(list(smiles_list)) #To ensure reproducibility
safe_list = []
for s in smiles_list:
hmol = MolGraph(s)
ok = True
for node,attr in hmol.mol_tree.nodes(data=True):
if attr['label'] not in self.vocab.vmap:
ok = False
if ok: safe_list.append(s)
if len(safe_list) > 0:
return MolGraph.tensorize(safe_list, self.vocab, self.avocab)
else:
return None
示例2: get_inter_label
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import MolToSmiles [as 别名]
def get_inter_label(mol, atoms, inter_atoms):
new_mol = get_clique_mol(mol, atoms)
if new_mol.GetNumBonds() == 0:
inter_atom = list(inter_atoms)[0]
for a in new_mol.GetAtoms():
a.SetAtomMapNum(0)
return new_mol, [ (inter_atom, Chem.MolToSmiles(new_mol)) ]
inter_label = []
for a in new_mol.GetAtoms():
idx = idxfunc(a)
if idx in inter_atoms and is_anchor(a, inter_atoms):
inter_label.append( (idx, get_anchor_smiles(new_mol, idx)) )
for a in new_mol.GetAtoms():
a.SetAtomMapNum( 1 if idxfunc(a) in inter_atoms else 0 )
return new_mol, inter_label
示例3: align
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import MolToSmiles [as 别名]
def align(xy_tuple):
x,y = xy_tuple
xmol, ymol = Chem.MolFromSmiles(x), Chem.MolFromSmiles(y)
x = Chem.MolToSmiles(xmol, isomericSmiles=False)
xmol = Chem.MolFromSmiles(x)
xleaf = get_leaves(xmol)
yleaf = get_leaves(ymol)
best_i,best_j = 0,0
best = 1000000
for i in xleaf:
for j in yleaf:
new_x = Chem.MolToSmiles(xmol, rootedAtAtom=i, isomericSmiles=False)
new_y = Chem.MolToSmiles(ymol, rootedAtAtom=j, isomericSmiles=False)
le = min(len(new_x), len(new_y)) // 2
dist = Levenshtein.distance(new_x[:le], new_y[:le])
if dist < best:
best_i, best_j = i, j
best = dist
return Chem.MolToSmiles(xmol, rootedAtAtom=best_i, isomericSmiles=False), Chem.MolToSmiles(ymol, rootedAtAtom=best_j, isomericSmiles=False)
示例4: _featurize
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import MolToSmiles [as 别名]
def _featurize(self, mol):
"""Featurizes a SMILES sequence."""
from rdkit import Chem
smile = Chem.MolToSmiles(mol)
if len(smile) > self.max_len:
return list()
smile_list = list(smile)
# Extend shorter strings with padding
if len(smile) < self.max_len:
smile_list.extend([PAD_TOKEN] * (self.max_len - len(smile)))
# Padding before and after
smile_list += [PAD_TOKEN] * self.pad_len
smile_list = [PAD_TOKEN] * self.pad_len + smile_list
smile_seq = self.to_seq(smile_list)
return smile_seq
示例5: featurize
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import MolToSmiles [as 别名]
def featurize(self, mols, verbose=True, log_every_n=1000):
"""
Parameters
----------
mols: obj
List of rdkit Molecule Objects
verbose: bool
How much logging
log_every_n:
How often to log
Returns
-------
obj
numpy array of features
"""
from rdkit import Chem
smiles = [Chem.MolToSmiles(mol) for mol in mols]
if self.charset is None:
self.charset = self._create_charset(smiles)
return np.array([self.one_hot_encoded(smile) for smile in smiles])
示例6: compute_all_ecfp
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import MolToSmiles [as 别名]
def compute_all_ecfp(mol, indices=None, degree=2):
"""Obtain molecular fragment for all atoms emanating outward to given degree.
For each fragment, compute SMILES string (for now) and hash to an int.
Return a dictionary mapping atom index to hashed SMILES.
"""
ecfp_dict = {}
from rdkit import Chem
for i in range(mol.GetNumAtoms()):
if indices is not None and i not in indices:
continue
env = Chem.FindAtomEnvironmentOfRadiusN(mol, degree, i, useHs=True)
submol = Chem.PathToSubmol(mol, env)
smile = Chem.MolToSmiles(submol)
ecfp_dict[i] = "%s,%s" % (mol.GetAtoms()[i].GetAtomicNum(), smile)
return ecfp_dict
示例7: score_candidates
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import MolToSmiles [as 别名]
def score_candidates(reactants, candidate_list, xs):
pred = model.predict(xs, batch_size = 20)[0]
rank = ss.rankdata(pred)
fname = raw_input('Enter file name to save to: ') + '.dat'
with open(os.path.join(FROOT, fname), 'w') as fid:
fid.write('FOR REACTANTS {}\n'.format(Chem.MolToSmiles(reactants)))
fid.write('Candidate product\tCandidate edit\tProbability\tRank\n')
for (c, candidate) in enumerate(candidate_list):
candidate_smile = candidate[0]
candidate_edit = candidate[1]
fid.write('{}\t{}\t{}\t{}\n'.format(
candidate_smile, candidate_edit, pred[c], 1 + len(pred) - rank[c]
))
print('Wrote to file {}'.format(os.path.join(FROOT, fname)))
示例8: decode_stereo
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import MolToSmiles [as 别名]
def decode_stereo(smiles2D):
mol = Chem.MolFromSmiles(smiles2D)
dec_isomers = list(EnumerateStereoisomers(mol))
dec_isomers = [Chem.MolFromSmiles(Chem.MolToSmiles(mol, isomericSmiles=True)) for mol in dec_isomers]
smiles3D = [Chem.MolToSmiles(mol, isomericSmiles=True) for mol in dec_isomers]
chiralN = [atom.GetIdx() for atom in dec_isomers[0].GetAtoms()
if int(atom.GetChiralTag()) > 0 and atom.GetSymbol() == "N"]
if len(chiralN) > 0:
for mol in dec_isomers:
for idx in chiralN:
mol.GetAtomWithIdx(idx).SetChiralTag(Chem.rdchem.ChiralType.CHI_UNSPECIFIED)
smiles3D.append(Chem.MolToSmiles(mol, isomericSmiles=True))
return smiles3D
示例9: load_sdf_files
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import MolToSmiles [as 别名]
def load_sdf_files(input_files, clean_mols):
"""Load SDF file into dataframe."""
dataframes = []
for input_file in input_files:
# Tasks are stored in .sdf.csv file
raw_df = next(load_csv_files([input_file + ".csv"], shard_size=None))
# Structures are stored in .sdf file
print("Reading structures from %s." % input_file)
suppl = Chem.SDMolSupplier(str(input_file), clean_mols, False, False)
df_rows = []
for ind, mol in enumerate(suppl):
if mol is not None:
smiles = Chem.MolToSmiles(mol)
df_rows.append([ind, smiles, mol])
mol_df = pd.DataFrame(df_rows, columns=('mol_id', 'smiles', 'mol'))
dataframes.append(pd.concat([mol_df, raw_df], axis=1, join='inner'))
return dataframes
示例10: decode_test
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import MolToSmiles [as 别名]
def decode_test():
wrong = 0
for tot,s in enumerate(sys.stdin):
s = s.split()[0]
tree = MolTree(s)
tree.recover()
cur_mol = copy_edit_mol(tree.nodes[0].mol)
global_amap = [{}] + [{} for node in tree.nodes]
global_amap[1] = {atom.GetIdx():atom.GetIdx() for atom in cur_mol.GetAtoms()}
dfs_assemble(cur_mol, global_amap, [], tree.nodes[0], None)
cur_mol = cur_mol.GetMol()
cur_mol = Chem.MolFromSmiles(Chem.MolToSmiles(cur_mol))
set_atommap(cur_mol)
dec_smiles = Chem.MolToSmiles(cur_mol)
gold_smiles = Chem.MolToSmiles(Chem.MolFromSmiles(s))
if gold_smiles != dec_smiles:
print gold_smiles, dec_smiles
wrong += 1
print wrong, tot + 1
示例11: randomize_smiles
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import MolToSmiles [as 别名]
def randomize_smiles(mol, random_type="restricted"):
"""
Returns a random SMILES given a SMILES of a molecule.
:param mol: A Mol object
:param random_type: The type (unrestricted, restricted) of randomization performed.
:return : A random SMILES string of the same molecule or None if the molecule is invalid.
"""
if not mol:
return None
if random_type == "unrestricted":
return rkc.MolToSmiles(mol, canonical=False, doRandom=True, isomericSmiles=False)
if random_type == "restricted":
new_atom_order = list(range(mol.GetNumAtoms()))
random.shuffle(new_atom_order)
random_mol = rkc.RenumberAtoms(mol, newOrder=new_atom_order)
return rkc.MolToSmiles(random_mol, canonical=False, isomericSmiles=False)
raise ValueError("Type '{}' is not valid".format(random_type))
示例12: get_rxn_smiles
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import MolToSmiles [as 别名]
def get_rxn_smiles(prod, reactants):
prod_smi = Chem.MolToSmiles(prod, True)
# Get rid of reactants when they don't contribute to this prod
prod_maps = set(re.findall('\:([[0-9]+)\]', prod_smi))
reactants_smi_list = []
for mol in reactants:
if mol is None:
continue
used = False
for a in mol.GetAtoms():
if a.HasProp('molAtomMapNumber'):
if a.GetProp('molAtomMapNumber') in prod_maps:
used = True
else:
a.ClearProp('molAtomMapNumber')
if used:
reactants_smi_list.append(Chem.MolToSmiles(mol, True))
reactants_smi = '.'.join(reactants_smi_list)
return '{}>>{}'.format(reactants_smi, prod_smi)
示例13: next_state
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import MolToSmiles [as 别名]
def next_state(self):
smiles = self.smiles
# TODO: this seems dodgy...
for i in range(100):
mol = add_atom(self.mol, self.stats)
smiles = Chem.MolToSmiles(mol)
if smiles != self.smiles:
break
next_state = State(scoring_function=self.scoring_function,
mol=mol,
smiles=smiles,
max_atoms=self.turn - 1,
max_children=self.max_children,
stats=self.stats,
seed=self.seed)
return next_state
示例14: _apply_transform
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import MolToSmiles [as 别名]
def _apply_transform(self, mol, rule):
"""Repeatedly apply normalization transform to molecule until no changes occur.
It is possible for multiple products to be produced when a rule is applied. The rule is applied repeatedly to
each of the products, until no further changes occur or after 20 attempts. If there are multiple unique products
after the final application, the first product (sorted alphabetically by SMILES) is chosen.
"""
mols = [mol]
for n in six.moves.range(20):
products = {}
for mol in mols:
for product in [x[0] for x in rule.RunReactants((mol,))]:
if Chem.SanitizeMol(product, catchErrors=True) == 0:
products[Chem.MolToSmiles(product, isomericSmiles=True)] = product
if products:
mols = [products[s] for s in sorted(products)]
else:
# If n == 0, the rule was not applicable and we return None
return mols[0] if n > 0 else None
示例15: load_fragments
# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import MolToSmiles [as 别名]
def load_fragments(fragments):
fragments = [Chem.MolToSmiles(Chem.MolFromSmiles(x)) for x in fragments]
MolGraph.FRAGMENTS = set(fragments)