當前位置: 首頁>>代碼示例>>Python>>正文


Python Chem.MolToSmiles方法代碼示例

本文整理匯總了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 
開發者ID:wengong-jin,項目名稱:hgraph2graph,代碼行數:21,代碼來源:dataset.py

示例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 
開發者ID:wengong-jin,項目名稱:hgraph2graph,代碼行數:19,代碼來源:chemutils.py

示例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) 
開發者ID:wengong-jin,項目名稱:hgraph2graph,代碼行數:24,代碼來源:align.py

示例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 
開發者ID:deepchem,項目名稱:deepchem,代碼行數:20,代碼來源:smiles_featurizers.py

示例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]) 
開發者ID:deepchem,項目名稱:deepchem,代碼行數:23,代碼來源:one_hot.py

示例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 
開發者ID:deepchem,項目名稱:deepchem,代碼行數:19,代碼來源:rdkit_grid_featurizer.py

示例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))) 
開發者ID:connorcoley,項目名稱:ochem_predict_nn,代碼行數:18,代碼來源:lowe_interactive_predict.py

示例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 
開發者ID:dmlc,項目名稱:dgl,代碼行數:18,代碼來源:chemutils.py

示例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 
開發者ID:simonfqy,項目名稱:PADME,代碼行數:19,代碼來源:save.py

示例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 
開發者ID:wengong-jin,項目名稱:icml18-jtnn,代碼行數:25,代碼來源:chemutils.py

示例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)) 
開發者ID:undeadpixel,項目名稱:reinvent-randomized,代碼行數:20,代碼來源:chem.py

示例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) 
開發者ID:Hanjun-Dai,項目名稱:GLN,代碼行數:23,代碼來源:clean_uspto.py

示例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 
開發者ID:BenevolentAI,項目名稱:guacamol_baselines,代碼行數:19,代碼來源:goal_directed_generation.py

示例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 
開發者ID:mcs07,項目名稱:MolVS,代碼行數:21,代碼來源:normalize.py

示例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) 
開發者ID:wengong-jin,項目名稱:hgraph2graph,代碼行數:5,代碼來源:mol_graph.py


注:本文中的rdkit.Chem.MolToSmiles方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。