当前位置: 首页>>代码示例>>Python>>正文


Python Chem.MolFromSmiles方法代码示例

本文整理汇总了Python中rdkit.Chem.MolFromSmiles方法的典型用法代码示例。如果您正苦于以下问题:Python Chem.MolFromSmiles方法的具体用法?Python Chem.MolFromSmiles怎么用?Python Chem.MolFromSmiles使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在rdkit.Chem的用法示例。


在下文中一共展示了Chem.MolFromSmiles方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __getitem__

# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import MolFromSmiles [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: align

# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import MolFromSmiles [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

示例3: setUp

# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import MolFromSmiles [as 别名]
def setUp(self):
    current_dir = os.path.dirname(os.path.realpath(__file__))

    # simple flat ring
    from rdkit.Chem import MolFromSmiles
    self.cycle4 = MolFromSmiles('C1CCC1')
    self.cycle4.Compute2DCoords()

    # load and sanitize two real molecules
    _, self.prot = rgf.load_molecule(
        os.path.join(current_dir, '3ws9_protein_fixer_rdkit.pdb'),
        add_hydrogens=False,
        calc_charges=False,
        sanitize=True)

    _, self.lig = rgf.load_molecule(
        os.path.join(current_dir, '3ws9_ligand.sdf'),
        add_hydrogens=False,
        calc_charges=False,
        sanitize=True) 
开发者ID:deepchem,项目名称:deepchem,代码行数:22,代码来源:test_rdkit_grid_features.py

示例4: main

# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import MolFromSmiles [as 别名]
def main() :
    model = models.KeyedVectors.load_word2vec_format("vec.txt")
    embeddings = list()

    # Using canonical smiles for glycine, as in original research paper
    mol = Chem.MolFromSmiles("C(C(=O)O)N")
    try:
        info = {}
        rdMolDescriptors.GetMorganFingerprint(mol, 0, bitInfo=info)
        keys = info.keys()
        keys_list = list(keys)
        totalvec = np.zeros(200)
        for k in keys_list:
            wordvec = model.wv[str(k)]
            totalvec = np.add(totalvec, wordvec)
        embeddings.append(totalvec)
    except Exception as e:
        print(e)
        pass

    print(embeddings[0]) 
开发者ID:deepchem,项目名称:deepchem,代码行数:23,代码来源:eval_mol2vec_results.py

示例5: construct_multigraph

# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import MolFromSmiles [as 别名]
def construct_multigraph(smile):
  g = OrderedDict({})
  h = OrderedDict({})

  molecule = Chem.MolFromSmiles(smile)
  for i in xrange(0, molecule.GetNumAtoms()):
    atom_i = molecule.GetAtomWithIdx(i)
    h[i] = Variable(torch.FloatTensor(dc.feat.graph_features.atom_features(atom_i))).view(1, 75)
    for j in xrange(0, molecule.GetNumAtoms()):
      e_ij = molecule.GetBondBetweenAtoms(i, j)
      if e_ij != None:
        e_ij =  map(lambda x: 1 if x == True else 0, dc.feat.graph_features.bond_features(e_ij)) # ADDED edge feat
        e_ij = Variable(torch.FloatTensor(e_ij).view(1, 6))
        atom_j = molecule.GetAtomWithIdx(j)
        if i not in g:
          g[i] = []
        g[i].append( (e_ij, j) )

  return g, h 
开发者ID:deepchem,项目名称:deepchem,代码行数:21,代码来源:mpnn.py

示例6: test_fit

# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import MolFromSmiles [as 别名]
def test_fit(self):
    tf_enc = TensorflowMoleculeEncoder.zinc_encoder()

    smiles = [
        "Cn1cnc2c1c(=O)n(C)c(=O)n2C", "O=C(O)[C@@H]1/C(=C/CO)O[C@@H]2CC(=O)N21",
        "Cn1c2nncnc2c(=O)n(C)c1=O", "Cn1cnc2c1c(=O)[nH]c(=O)n2C",
        "NC(=O)c1ncc[nH]c1=O", "O=C1OCc2c1[nH]c(=O)[nH]c2=O",
        "Cn1c(N)c(N)c(=O)n(C)c1=O", "CNc1nc2c([nH]1)c(=O)[nH]c(=O)n2C",
        "CC(=O)N1CN(C(C)=O)[C@@H](O)[C@@H]1O",
        "CC(=O)N1CN(C(C)=O)[C@H](O)[C@H]1O", "Cc1[nH]c(=O)[nH]c(=O)c1CO",
        "O=C1NCCCc2c1no[n+]2[O-]", "Cc1nc(C(N)=O)c(N)n1CCO",
        "O=c1[nH]cc(N2CCOCC2)c(=O)[nH]1"
    ]

    featurizer = dc.feat.one_hot.OneHotFeaturizer(zinc_charset, 120)
    mols = [Chem.MolFromSmiles(x) for x in smiles]
    features = featurizer.featurize(mols)

    dataset = DiskDataset.from_numpy(features, features)
    prediction = tf_enc.predict_on_batch(dataset.X)
    tf_de = TensorflowMoleculeDecoder.zinc_decoder()
    one_hot_decoded = tf_de.predict_on_batch(prediction)
    decoded_smiles = featurizer.untransform(one_hot_decoded)
    assert len(decoded_smiles) == len(smiles) 
开发者ID:deepchem,项目名称:deepchem,代码行数:26,代码来源:test_tensorflowEncoders.py

示例7: __getitem__

# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import MolFromSmiles [as 别名]
def __getitem__(self, item):
    """
    Returns an rdkit mol object
    :param item:
    :return:
    """
    smiles = self.df['smiles'][item]
    mol = Chem.MolFromSmiles(smiles)
    return mol

# # TESTS
# path = 'gdb13.rand1M.smi.gz'
# dataset = gdb_dataset(path)
#
# print(len(dataset))
# mol,_ = dataset[0]
# graph = mol_to_nx(mol)
# graph_sub = graph.subgraph([0,3,5,7,9])
# graph_sub_new = nx.convert_node_labels_to_integers(graph_sub,label_attribute='old')
# graph_sub_node = graph_sub.nodes()
# graph_sub_new_node = graph_sub_new.nodes()
# matrix = nx.adjacency_matrix(graph_sub)
# np_matrix = matrix.toarray()
# print(np_matrix)
# print('end') 
开发者ID:bowenliu16,项目名称:rl_graph_generation,代码行数:27,代码来源:dataset_utils.py

示例8: featurize_smiles_np

# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import MolFromSmiles [as 别名]
def featurize_smiles_np(arr, featurizer, log_every_N=1000, verbose=True):
  """Featurize individual compounds in a numpy array.

  Given a featurizer that operates on individual chemical compounds
  or macromolecules, compute & add features for that compound to the
  features array
  """
  features = []
  for ind, elem in enumerate(arr.tolist()):
    mol = Chem.MolFromSmiles(elem)
    if mol:
      new_order = rdmolfiles.CanonicalRankAtoms(mol)
      mol = rdmolops.RenumberAtoms(mol, new_order)
    if ind % log_every_N == 0:
      log("Featurizing sample %d" % ind, verbose)
    features.append(featurizer.featurize([mol]))

  valid_inds = np.array(
      [1 if elt.size > 0 else 0 for elt in features], dtype=bool)
  features = [elt for (is_valid, elt) in zip(valid_inds, features) if is_valid]
  features = np.squeeze(np.array(features))
  return features.reshape(-1,) 
开发者ID:simonfqy,项目名称:PADME,代码行数:24,代码来源:data_loader.py

示例9: _generateMolFrags

# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import MolFromSmiles [as 别名]
def _generateMolFrags(datachunk, vocabulary, fragmentMethod, fragIdx=None):
    if fragIdx is None and fragmentMethod == 'Brics':
        return
    result={}
    for idx, smi in datachunk:
        mol = Chem.MolFromSmiles(str(smi))
        if mol == None:
            continue
        fp,_=_generateFPs(mol,fragmentMethod=fragmentMethod)
        if fp is None:
            continue
        tmp={}
        for k,v in fp.items():
            if k not in vocabulary:
                continue
            # save memory: for BRICS use index instead of long complicated SMILES
            if fragmentMethod == 'Brics':
                tmp[fragIdx[k]]=v
            else:
                tmp[k]=v
        result[idx]=tmp
    return result

########### chemical topic modeling class ################### 
开发者ID:rdkit,项目名称:CheTo,代码行数:26,代码来源:chemTopicModel.py

示例10: getSubstructSmi

# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import MolFromSmiles [as 别名]
def getSubstructSmi(mol,env,propsToSmiles=True):
    """

    >>> getSubstructSmi(Chem.MolFromSmiles('Cc1ncccc1'),((0,1,2)))
    '[cH;R;D2]:[n;R;D2]:[c;R;D3]-[CH3;R0;D1]'

    """
    atomsToUse=set()
    if not len(env):
        return ''
    for b in env:
        atomsToUse.add(mol.GetBondWithIdx(b).GetBeginAtomIdx())
        atomsToUse.add(mol.GetBondWithIdx(b).GetEndAtomIdx())
    # no isomeric smiles since we don't include that in the fingerprints
    smi = Chem.MolFragmentToSmiles(mol,atomsToUse,isomericSmiles=False,
                                   bondsToUse=env,allHsExplicit=True, allBondsExplicit=True)
    if propsToSmiles:
        order = eval(mol.GetProp("_smilesAtomOutputOrder"))
        smi = writePropsToSmiles(mol,smi,order)
    return smi 
开发者ID:rdkit,项目名称:CheTo,代码行数:22,代码来源:utilsFP.py

示例11: generateAtomInvariant

# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import MolFromSmiles [as 别名]
def generateAtomInvariant(mol):
    """

    >>> generateAtomInvariant(Chem.MolFromSmiles("Cc1ncccc1"))
    [341294046, 3184205312, 522345510, 1545984525, 1545984525, 1545984525, 1545984525]

    """
    num_atoms = mol.GetNumAtoms()
    invariants = [0]*num_atoms
    for i,a in enumerate(mol.GetAtoms()):
        descriptors=[]
        descriptors.append(a.GetAtomicNum())
        descriptors.append(a.GetTotalDegree())
        descriptors.append(a.GetTotalNumHs())
        descriptors.append(a.IsInRing())
        descriptors.append(a.GetIsAromatic())
        invariants[i]=hash(tuple(descriptors))& 0xffffffff
    return invariants


#------------------------------------
#
#  doctest boilerplate
# 
开发者ID:rdkit,项目名称:CheTo,代码行数:26,代码来源:utilsFP.py

示例12: count_inters

# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import MolFromSmiles [as 别名]
def count_inters(s):
    mol = Chem.MolFromSmiles(s)
    inters = [a for a in mol.GetAtoms() if a.GetAtomMapNum() > 0]
    return max(1, len(inters)) 
开发者ID:wengong-jin,项目名称:hgraph2graph,代码行数:6,代码来源:vocab.py

示例13: load_fragments

# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import MolFromSmiles [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

示例14: get_mol

# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import MolFromSmiles [as 别名]
def get_mol(smiles):
    mol = Chem.MolFromSmiles(smiles)
    if mol is not None: Chem.Kekulize(mol)
    return mol 
开发者ID:wengong-jin,项目名称:hgraph2graph,代码行数:6,代码来源:chemutils.py

示例15: sanitize

# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import MolFromSmiles [as 别名]
def sanitize(mol, kekulize=True):
    try:
        smiles = get_smiles(mol) if kekulize else Chem.MolToSmiles(mol)
        mol = get_mol(smiles) if kekulize else Chem.MolFromSmiles(smiles)
    except:
        mol = None
    return mol 
开发者ID:wengong-jin,项目名称:hgraph2graph,代码行数:9,代码来源:chemutils.py


注:本文中的rdkit.Chem.MolFromSmiles方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。