Commit 30f8734a authored by aksub99's avatar aksub99
Browse files

Fix yapf format

parent 0f89567a
Loading
Loading
Loading
Loading
+18 −15
Original line number Diff line number Diff line
@@ -5,13 +5,15 @@ from collections import defaultdict
from deepchem.utils.typing import PymatgenComposition
from deepchem.feat import MaterialCompositionFeaturizer


elements_tl = ['H', 'Li', 'Be', 'B', 'C', 'N', 'O', 'F', 'Na', 'Mg', 'Al', 'Si', 'P', 'S', 'Cl', 'K',
 'Ca', 'Sc', 'Ti', 'V', 'Cr', 'Mn', 'Fe', 'Co', 'Ni', 'Cu', 'Zn', 'Ga', 'Ge', 'As', 'Se',
 'Br', 'Kr', 'Rb', 'Sr', 'Y', 'Zr', 'Nb', 'Mo', 'Tc', 'Ru', 'Rh', 'Pd', 'Ag', 'Cd', 'In',
 'Sn', 'Sb', 'Te', 'I', 'Xe', 'Cs', 'Ba', 'La', 'Ce', 'Pr', 'Nd', 'Pm', 'Sm', 'Eu', 'Gd',
 'Tb', 'Dy', 'Ho', 'Er', 'Tm', 'Yb', 'Lu', 'Hf', 'Ta', 'W', 'Re', 'Os', 'Ir', 'Pt', 'Au',
 'Hg', 'Tl', 'Pb', 'Bi', 'Ac','Th', 'Pa', 'U', 'Np', 'Pu']
elements_tl = [
    'H', 'Li', 'Be', 'B', 'C', 'N', 'O', 'F', 'Na', 'Mg', 'Al', 'Si', 'P', 'S',
    'Cl', 'K', 'Ca', 'Sc', 'Ti', 'V', 'Cr', 'Mn', 'Fe', 'Co', 'Ni', 'Cu', 'Zn',
    'Ga', 'Ge', 'As', 'Se', 'Br', 'Kr', 'Rb', 'Sr', 'Y', 'Zr', 'Nb', 'Mo', 'Tc',
    'Ru', 'Rh', 'Pd', 'Ag', 'Cd', 'In', 'Sn', 'Sb', 'Te', 'I', 'Xe', 'Cs', 'Ba',
    'La', 'Ce', 'Pr', 'Nd', 'Pm', 'Sm', 'Eu', 'Gd', 'Tb', 'Dy', 'Ho', 'Er',
    'Tm', 'Yb', 'Lu', 'Hf', 'Ta', 'W', 'Re', 'Os', 'Ir', 'Pt', 'Au', 'Hg', 'Tl',
    'Pb', 'Bi', 'Ac', 'Th', 'Pa', 'U', 'Np', 'Pu'
]

formulare = re.compile(r'([A-Z][a-z]*)(\d*\.*\d*)')

@@ -40,8 +42,10 @@ class CompositionFeaturizer(MaterialCompositionFeaturizer):

  def get_fractions(self, comp):
    if all(e in elements_tl for e in comp):
        return np.array([comp[e] if e in comp else 0 for e in elements_tl], np.float32)
    else:   return None
      return np.array([comp[e] if e in comp else 0 for e in elements_tl],
                      np.float32)
    else:
      return None

  def parse_fractions(self, form):
    while '/' in form:
@@ -57,11 +61,9 @@ class CompositionFeaturizer(MaterialCompositionFeaturizer):
    curr_str = ''
    i = 0
    res = defaultdict(int)
    formula = formula.replace('-', '').replace('@',
                                               '').replace(' ', '').replace('[', '(').replace(']', ')').replace('{',
                                                                                                                '(').replace(
        '}',
        ')').replace('@', '').replace('x', '').replace(' ', '')
    formula = formula.replace('-', '').replace('@', '').replace(
        ' ', '').replace('[', '(').replace(']', ')').replace('{', '(').replace(
            '}', ')').replace('@', '').replace('x', '').replace(' ', '')

    def parse_simple_formula(x):
      x = self.parse_fractions(x)
@@ -123,7 +125,8 @@ class CompositionFeaturizer(MaterialCompositionFeaturizer):
    if any([e for e in res if e in ['T', 'D', 'G', 'M', 'Q']]):
      print(formula, res)
    sum_nums = 1. * sum(res.values())
    for k in res: res[k] = 1. * res[k] / sum_nums
    for k in res:
      res[k] = 1. * res[k] / sum_nums
    return res

  def _featurize(self, composition: PymatgenComposition) -> np.ndarray: