Exemple #1
0
def GetAtomBagAndCharge(molstring):
    formula, formal_charge = GetFormulaAndCharge(molstring)
    periodic_table = rdchem.GetPeriodicTable()

    atom_bag = {}
    for mol_formula_times in formula.split('.'):
        for times, mol_formula in re.findall('^(\d+)?(\w+)',
                                             mol_formula_times):
            if not times:
                times = 1
            else:
                times = int(times)
            for atom, count in re.findall("([A-Z][a-z]*)([0-9]*)",
                                          mol_formula):
                if count == '':
                    count = 1
                else:
                    count = int(count)
                atom_bag[atom] = atom_bag.get(atom, 0) + count * times

    n_protons = sum([
        c * periodic_table.GetAtomicNumber(str(elem))
        for (elem, c) in atom_bag.items()
    ])
    atom_bag['e-'] = n_protons - formal_charge

    return atom_bag, formal_charge
Exemple #2
0
# -*- coding: utf-8 -*-
"""
Created on Sun Sep  1 18:04:35 2019

@note: the varies topology indexes are calculated 
"""

from rdkit import Chem
from rdkit.Chem import rdchem
from rdkit.Chem import GraphDescriptors as GD

import numba as nb
import numpy as np
import scipy

periodicTable = rdchem.GetPeriodicTable()

MINVALUE = 1e-8


@nb.njit()
def _graphdist_(Distance):
    """
    Calculation of graph distance index: Tigdi(log value),
    The graph distance index is defined as the squared sum of all graph distance counts
    """
    unique = np.unique(Distance)
    res = MINVALUE
    for i in unique:
        k1 = Distance == i
        temp = k1.sum()