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


Python Chem.Kekulize方法代码示例

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


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

示例1: MolToQPixmap

# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import Kekulize [as 别名]
def MolToQPixmap(mol, size=(300, 300), kekulize=True, wedgeBonds=True, fitImage=False, options=None,
                 **kwargs):
    """ Generates a drawing of a molecule on a Qt QPixmap
      """
    if not mol:
        raise ValueError('Null molecule provided')
    from rdkit.Chem.Draw.qtCanvas import Canvas
    canvas = Canvas(size)
    if options is None:
        options = DrawingOptions()
    options.bgColor = None
    if fitImage:
        options.dotsPerAngstrom = int(min(size) / 10)
    options.wedgeDashedBonds = wedgeBonds
    if kekulize:
        from rdkit import Chem
        mol = Chem.Mol(mol.ToBinary())
        Chem.Kekulize(mol)
    if not mol.GetNumConformers():
        from rdkit.Chem import AllChem
        AllChem.Compute2DCoords(mol)
    drawer = MolDrawing(canvas=canvas, drawingOptions=options)
    drawer.AddMol(mol, **kwargs)
    canvas.flush()
    return canvas.pixmap 
开发者ID:blackmints,项目名称:3DGCN,代码行数:27,代码来源:__init__.py

示例2: sanitizeMol

# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import Kekulize [as 别名]
def sanitizeMol(self, kekulize=False, drawkekulize=False):
        self.computeNewCoords()
        self._drawmol = Chem.Mol(self._mol.ToBinary()) #Is this necessary?
        try:
            Chem.SanitizeMol(self._drawmol)
            self.sanitizeSignal.emit("Sanitizable")
        except:
            self.sanitizeSignal.emit("UNSANITIZABLE")
            self.logger.warning("Unsanitizable")
            try:
                self._drawmol.UpdatePropertyCache(strict=False)
            except:
                self.sanitizeSignal.emit("UpdatePropertyCache FAIL")
                self.logger.error("Update Property Cache failed")
        #Kekulize
        if kekulize:
            try:
                Chem.Kekulize(self._drawmol)
            except:
                self.logger.warning("Unkekulizable")
        try:
            self._drawmol = rdMolDraw2D.PrepareMolForDrawing(self._drawmol, kekulize=drawkekulize)
        except ValueError:  # <- can happen on a kekulization failure
            self._drawmol = rdMolDraw2D.PrepareMolForDrawing(self._drawmol, kekulize=False) 
开发者ID:EBjerrum,项目名称:rdeditor,代码行数:26,代码来源:molViewWidget.py

示例3: crossover

# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import Kekulize [as 别名]
def crossover(parent_A,parent_B):
  parent_smiles = [Chem.MolToSmiles(parent_A),Chem.MolToSmiles(parent_B)]
  try:
	  Chem.Kekulize(parent_A,clearAromaticFlags=True)
	  Chem.Kekulize(parent_B,clearAromaticFlags=True)
  except:
  	pass
  for i in range(10):
    if random.random() <= 0.5:
      #print 'non-ring crossover'
      new_mol = crossover_non_ring(parent_A,parent_B)
      if new_mol != None:
        new_smiles = Chem.MolToSmiles(new_mol)
      if new_mol != None and new_smiles not in parent_smiles:
        return new_mol
    else:
      #print 'ring crossover'
      new_mol = crossover_ring(parent_A,parent_B)
      if new_mol != None:
        new_smiles = Chem.MolToSmiles(new_mol)
      if new_mol != None and new_smiles not in parent_smiles:
        return new_mol
  
  return None 
开发者ID:jensengroup,项目名称:GB-GA,代码行数:26,代码来源:crossover.py

示例4: prepare_smiles_and_mol

# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import Kekulize [as 别名]
def prepare_smiles_and_mol(self, mol):
        """Prepare `smiles` and `mol` used in following preprocessing.

        This method is called before `get_input_features` is called, by parser
        class.
        This method may be overriden to support custom `smile`/`mol` extraction

        Args:
            mol (mol): mol instance

        Returns (tuple): (`smiles`, `mol`)
        """
        # Note that smiles expression is not unique.
        # we obtain canonical smiles which is unique in `mol`
        canonical_smiles = Chem.MolToSmiles(mol, isomericSmiles=False,
                                            canonical=True)
        mol = Chem.MolFromSmiles(canonical_smiles)
        if self.add_Hs:
            mol = Chem.AddHs(mol)
        if self.kekulize:
            Chem.Kekulize(mol)
        return canonical_smiles, mol 
开发者ID:chainer,项目名称:chainer-chemistry,代码行数:24,代码来源:mol_preprocessor.py

示例5: get_mol

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

示例6: MolToFile

# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import Kekulize [as 别名]
def MolToFile(mol, fileName, size=(300, 300), kekulize=True, wedgeBonds=True, imageType=None,
              fitImage=False, options=None, **kwargs):
    """ Generates a drawing of a molecule and writes it to a file
    """
    # original contribution from Uwe Hoffmann
    if not fileName:
        raise ValueError('no fileName provided')
    if not mol:
        raise ValueError('Null molecule provided')

    if imageType is None:
        imageType = os.path.splitext(fileName)[1][1:]

    if options is None:
        options = DrawingOptions()
    useAGG, useCairo, Canvas = _getCanvas()
    if fitImage:
        options.dotsPerAngstrom = int(min(size) / 10)
    options.wedgeDashedBonds = wedgeBonds
    if useCairo or useAGG:
        canvas = Canvas(size=size, imageType=imageType, fileName=fileName)
    else:
        options.radicalSymbol = '.'  # <- the sping canvas doesn't support unicode well
        canvas = Canvas(size=size, name=fileName, imageType=imageType)
    drawer = MolDrawing(canvas=canvas, drawingOptions=options)
    if kekulize:
        from rdkit import Chem
        mol = Chem.Mol(mol.ToBinary())
        Chem.Kekulize(mol)

    if not mol.GetNumConformers():
        from rdkit.Chem import AllChem
        AllChem.Compute2DCoords(mol)

    drawer.AddMol(mol, **kwargs)
    if useCairo or useAGG:
        canvas.flush()
    else:
        canvas.save() 
开发者ID:blackmints,项目名称:3DGCN,代码行数:41,代码来源:__init__.py

示例7: MolToMPL

# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import Kekulize [as 别名]
def MolToMPL(mol, size=(300, 300), kekulize=True, wedgeBonds=True, imageType=None, fitImage=False,
             options=None, **kwargs):
    """ Generates a drawing of a molecule on a matplotlib canvas
    """
    if not mol:
        raise ValueError('Null molecule provided')
    from experiment.figure.Draw.mplCanvas import Canvas
    canvas = Canvas(size)
    if options is None:
        options = DrawingOptions()
        options.bgColor = None
    if fitImage:
        options.dotsPerAngstrom = int(min(size) / 10)
    options.wedgeDashedBonds = wedgeBonds
    drawer = MolDrawing(canvas=canvas, drawingOptions=options)
    omol = mol
    if kekulize:
        from rdkit import Chem
        mol = Chem.Mol(mol.ToBinary())
        Chem.Kekulize(mol)

    if not mol.GetNumConformers():
        from rdkit.Chem import AllChem
        AllChem.Compute2DCoords(mol)

    drawer.AddMol(mol, **kwargs)
    omol._atomPs = drawer.atomPs[mol]
    for k, v in iteritems(omol._atomPs):
        omol._atomPs[k] = canvas.rescalePt(v)
    canvas._figure.set_size_inches(float(size[0]) / 100, float(size[1]) / 100)
    return canvas._figure 
开发者ID:blackmints,项目名称:3DGCN,代码行数:33,代码来源:__init__.py

示例8: get_mol

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

示例9: get_molecule

# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import Kekulize [as 别名]
def get_molecule(molecule_strs, kekulize) -> AllChem.Mol:
    """
    Convert string to molecule
    """
    mol = Chem.MolFromSmiles(molecule_strs)
    if kekulize:
        Chem.Kekulize(mol)
    return mol 
开发者ID:john-bradshaw,项目名称:molecule-chef,代码行数:10,代码来源:rdkit_general_ops.py

示例10: get_product_smiles

# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import Kekulize [as 别名]
def get_product_smiles(rmol, edits, tatoms):
    smiles = edit_mol(rmol, edits, tatoms)
    if len(smiles) != 0: return smiles
    try:
        Chem.Kekulize(rmol)
    except Exception as e:
        return smiles
    return edit_mol(rmol, edits, tatoms) 
开发者ID:wengong-jin,项目名称:nips17-rexgen,代码行数:10,代码来源:edit_mol.py

示例11: crossover

# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import Kekulize [as 别名]
def crossover(parent_A, parent_B):
    parent_smiles = [Chem.MolToSmiles(parent_A), Chem.MolToSmiles(parent_B)]
    try:
        Chem.Kekulize(parent_A, clearAromaticFlags=True)
        Chem.Kekulize(parent_B, clearAromaticFlags=True)

    except ValueError:
        pass

    for i in range(10):
        if random.random() <= 0.5:
            # print 'non-ring crossover'
            new_mol = crossover_non_ring(parent_A, parent_B)
            if new_mol is not None:
                new_smiles = Chem.MolToSmiles(new_mol)
                if new_smiles is not None and new_smiles not in parent_smiles:
                    return new_mol
        else:
            # print 'ring crossover'
            new_mol = crossover_ring(parent_A, parent_B)
            if new_mol is not None:
                new_smiles = Chem.MolToSmiles(new_mol)
                if new_smiles is not None and new_smiles not in parent_smiles:
                    return new_mol

    return None 
开发者ID:BenevolentAI,项目名称:guacamol_baselines,代码行数:28,代码来源:crossover.py

示例12: mutate

# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import Kekulize [as 别名]
def mutate(mol, mutation_rate):
    if random.random() > mutation_rate:
        return mol

    try:
        Chem.Kekulize(mol, clearAromaticFlags=True)
    except ValueError:
        return mol

    p = [0.15, 0.14, 0.14, 0.14, 0.14, 0.14, 0.15]
    for i in range(10):
        rxn_smarts_list = 7 * ['']
        rxn_smarts_list[0] = insert_atom()
        rxn_smarts_list[1] = change_bond_order()
        rxn_smarts_list[2] = delete_cyclic_bond()
        rxn_smarts_list[3] = add_ring()
        rxn_smarts_list[4] = delete_atom()
        rxn_smarts_list[5] = change_atom(mol)
        rxn_smarts_list[6] = append_atom()
        rxn_smarts = np.random.choice(rxn_smarts_list, p=p)

        # print 'mutation',rxn_smarts

        rxn = AllChem.ReactionFromSmarts(rxn_smarts)

        new_mol_trial = rxn.RunReactants((mol,))

        new_mols = []
        for m in new_mol_trial:
            m = m[0]
            # print Chem.MolToSmiles(mol),mol_ok(mol)
            if co.mol_ok(m) and co.ring_OK(m):
                new_mols.append(m)

        if len(new_mols) > 0:
            return random.choice(new_mols)

    return None 
开发者ID:BenevolentAI,项目名称:guacamol_baselines,代码行数:40,代码来源:mutate.py

示例13: get_counts

# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import Kekulize [as 别名]
def get_counts(smarts_list, smiles_list, ring=False) -> Tuple[int, Dict[str, int]]:
    """

    Args:
        smarts_list: list of SMARTS of intrest
        smiles_list: a list of SMILES strings
        ring: determines whether or not the matches are uniquified

    Returns:
        tot: sum of SMARTS counts
        probs2: an OrderedDict of {SMART: counts}

    """
    probs = collections.OrderedDict()

    for smarts in smarts_list:
        probs[smarts] = 0

    # number_of_molecules = 0
    # tot = 0
    for smiles in smiles_list:
        # print smiles
        # number_of_molecules += 1
        mol = Chem.MolFromSmiles(smiles)
        Chem.Kekulize(mol)
        for smarts in smarts_list:
            matches = mol.GetSubstructMatches(Chem.MolFromSmarts(smarts), uniquify=ring)
            num_bonds = len(matches)  # not the number of bonds, but the number of matches
            probs[smarts] += num_bonds
            # tot += num_bonds

    tot = 0
    probs2 = collections.OrderedDict()
    for key in probs:
        if probs[key] > 0:
            # print key, probs[key]
            tot += probs[key]
            probs2[key] = probs[key]

    return tot, probs2 
开发者ID:BenevolentAI,项目名称:guacamol_baselines,代码行数:42,代码来源:analyze_dataset.py

示例14: count_macro_cycles

# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import Kekulize [as 别名]
def count_macro_cycles(smiles_list, smarts_list, tot, probs):
    """

    Args:
        smiles_list: list of SMILES
        smarts_list: list of SMARTS
        tot: counter of ... TODO: why is this passed?
        probs: OrderedDict of {SMARTS: counts}

    Returns:

    """
    # probs = collections.OrderedDict()
    for smarts in smarts_list:
        probs[smarts] = 0

    for smiles in smiles_list:
        for smarts in smarts_list:
            mol = Chem.MolFromSmiles(smiles)
            Chem.Kekulize(mol)
            matches = mol.GetSubstructMatches(Chem.MolFromSmarts(smarts), uniquify=True)
            if len(matches) > 0:
                probs[smarts] += 1
                tot += 1

    return tot, probs 
开发者ID:BenevolentAI,项目名称:guacamol_baselines,代码行数:28,代码来源:analyze_dataset.py

示例15: run_rxn

# 需要导入模块: from rdkit import Chem [as 别名]
# 或者: from rdkit.Chem import Kekulize [as 别名]
def run_rxn(rxn_smarts, mol):
    new_mol_list = []
    patt = rxn_smarts.split('>>')[0]
    # work on a copy so an un-kekulized version is returned
    # if the molecule is not changed
    mol_copy = Chem.Mol(mol)
    try:
        Chem.Kekulize(mol_copy)
    except ValueError:
        pass
    if mol_copy.HasSubstructMatch(Chem.MolFromSmarts(patt)):
        rxn = AllChem.ReactionFromSmarts(rxn_smarts)
        new_mols = rxn.RunReactants((mol_copy,))
        for new_mol in new_mols:
            try:
                Chem.SanitizeMol(new_mol[0])
                new_mol_list.append(new_mol[0])
            except ValueError:
                pass
        if len(new_mol_list) > 0:
            new_mol = random.choice(new_mol_list)
            return new_mol
        else:
            return mol
    else:
        return mol 
开发者ID:BenevolentAI,项目名称:guacamol_baselines,代码行数:28,代码来源:goal_directed_generation.py


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