Commit 867f0aab authored by VIGNESHinZONE's avatar VIGNESHinZONE
Browse files

Fixed docstrings and removed test functions

parent 4eb804f9
Loading
Loading
Loading
Loading
+6 −21
Original line number Diff line number Diff line
@@ -5,6 +5,8 @@ from collections import defaultdict
from typing import List, Dict, Tuple, DefaultDict, Any
from deepchem.utils.typing import PymatgenStructure
from deepchem.feat.graph_data import GraphData
from scipy.spatial.distance import pdist, squareform, cdist
from scipy.spatial.transform import Rotation


class LCNNFeaturizer(MaterialStructureFeaturizer):
@@ -17,10 +19,10 @@ class LCNNFeaturizer(MaterialStructureFeaturizer):
  determined by first extracting a site local environment from the primitive cell,
  and perform graph matching and distance matching to find neighbors.
  First, the template of the Primitive cell needs to be defined along with periodic
  boundary conditions and active and specator site details. structure(Data Point
  boundary conditions and active and spectator site details. structure(Data Point
  i.e different configuration of adsorbate atoms) is passed for featurization.

  This particular featurisation produces a regular-graph (equal number of Neighbors)
  This particular featurization produces a regular-graph (equal number of Neighbors)
  along with its permutation in 6 symmetric axis. This transformation can be
  applied when orderering of neighboring of nodes around a site play an important role
  in the propert predictions. Due to consideration of local neighbor environment,
@@ -226,10 +228,6 @@ class _SiteEnvironment(object):
      import networkx.algorithms.isomorphism as iso
    except:
      raise ImportError("This class requires networkx to be installed.")
    try:
      from scipy.spatial.distance import pdist, squareform
    except:
      raise ImportError("This class requires scipy to be installed.")
    self.pos = pos
    self.sitetypes = sitetypes
    self.activesiteidx = [i for i, s in enumerate(self.sitetypes) if 'A' in s]
@@ -294,11 +292,6 @@ class _SiteEnvironment(object):
    except:
      raise ImportError("This class requires networkx to be installed.")

    try:
      from scipy.spatial.distance import cdist, pdist
    except:
      raise ImportError("This class requires scipy to be installed.")

    # construct graph
    G = nx.Graph()
    dists = cdist([[0, 0, 0]], pos - np.mean(pos, 0))[0]
@@ -347,10 +340,6 @@ class _SiteEnvironment(object):
      import networkx.algorithms.isomorphism as iso
    except:
      raise ImportError("This class requires networkx to be installed.")
    try:
      from scipy.spatial.transform import Rotation
    except:
      raise ImportError("This class requires scipy to be installed.")
    # construct graph

    G = self._construct_graph(env['pos'], env['sitetypes'])
@@ -635,10 +624,6 @@ def _get_SiteEnvironments(struct: PymatgenStructure,
  except:
    raise ImportError("This class requires pymatgen to be installed.")

  try:
    from scipy.spatial.distance import cdist
  except:
    raise ImportError("This class requires scipy to be installed.")
  pbc = np.array(PBC)
  structure = struct
  neighbors = structure.get_all_neighbors(cutoff, include_index=True)
+0 −486
Original line number Diff line number Diff line
{
    "primitive_cell": {
        "cutoff": 6.0,
        "structure": {
            "@module":
            "pymatgen.core.structure",
            "@class":
            "Structure",
            "charge":
            null,
            "lattice": {
                "matrix": [[2.818528, 0.0, 0.0], [-1.409264, 2.440917, 0.0],
                           [0.0, 0.0, 25.508255]],
                "a":
                2.818528,
                "b":
                2.8185281305293013,
                "c":
                25.508255,
                "alpha":
                90.0,
                "beta":
                90.0,
                "gamma":
                119.99999846803924,
                "volume":
                175.4915118999615
            },
            "sites": [{
                "species": [{
                    "element": "H",
                    "occu": 1
                }],
                "abc": [0.66667, 0.33333, 0.090221],
                "xyz":
                [1.4092780926400001, 0.8136308636099999, 2.3013802743549996],
                "label":
                "H",
                "properties": {
                    "SiteTypes": "S1"
                }
            }, {
                "species": [{
                    "element": "H",
                    "occu": 1
                }],
                "abc": [0.33333, 0.66667, 0.18043936],
                "xyz":
                [-1.409263999996302e-5, 1.6272861363899997, 4.6026932069168],
                "label":
                "H",
                "properties": {
                    "SiteTypes": "S1"
                }
            }, {
                "species": [{
                    "element": "H",
                    "occu": 1
                }],
                "abc": [0.0, 0.0, 0.27065772],
                "xyz": [0.0, 0.0, 6.904006139478599],
                "label": "H",
                "properties": {
                    "SiteTypes": "S1"
                }
            }, {
                "species": [{
                    "element": "H",
                    "occu": 1
                }],
                "abc": [0.66667, 0.33333, 0.36087608],
                "xyz":
                [1.4092780926400001, 0.8136308636099999, 9.2053190720404],
                "label":
                "H",
                "properties": {
                    "SiteTypes": "S1"
                }
            }, {
                "species": [{
                    "element": "H",
                    "occu": 1
                }],
                "abc": [0.33333, 0.66667, 0.45109444],
                "xyz":
                [-1.409263999996302e-5, 1.6272861363899997, 11.5066320046022],
                "label":
                "H",
                "properties": {
                    "SiteTypes": "S1"
                }
            }, {
                "species": [{
                    "element": "He",
                    "occu": 1
                }],
                "abc": [0.0, 0.0, 0.49656991],
                "xyz": [0.0, 0.0, 12.66663188960705],
                "label": "He",
                "properties": {
                    "SiteTypes": "A1"
                }
            }]
        },
        "aos": ["1", "0", "2"],
        "pbc": [true, true, false],
        "ns": 1,
        "na": 1
    },
    "data point": {
        "@module":
        "pymatgen.core.structure",
        "@class":
        "Structure",
        "charge":
        null,
        "lattice": {
            "matrix": [[-4.227792, -2.440917, 0.0], [2.818528, -4.881834, 0.0],
                       [0.0, 0.0, 23.17559]],
            "a":
            4.881833773916621,
            "b":
            5.637056261058603,
            "c":
            23.17559,
            "alpha":
            90.0,
            "beta":
            90.0,
            "gamma":
            89.99999693607845,
            "volume":
            637.7730390845832
        },
        "sites": [{
            "species": [{
                "element": "H",
                "occu": 1
            }],
            "abc": [0.33333, 0.5, 0.099298999982],
            "xyz":
            [1.4092640000074041e-5, -3.2545478636099996, 2.301312910992839],
            "label":
            "H",
            "properties": {
                "SiteTypes": "S1",
                "oss": "-1"
            }
        }, {
            "species": [{
                "element": "H",
                "occu": 1
            }],
            "abc": [0.0, 0.5, 0.198598000008],
            "xyz": [1.409264, -2.440917, 4.602625823005404],
            "label": "H",
            "properties": {
                "SiteTypes": "S1",
                "oss": "-1"
            }
        }, {
            "species": [{
                "element": "H",
                "occu": 1
            }],
            "abc": [0.16667, 0.25, 0.297897000033],
            "xyz": [-1.409263999996302e-5, -1.62728613639, 6.903938734994795],
            "label":
            "H",
            "properties": {
                "SiteTypes": "S1",
                "oss": "-1"
            }
        }, {
            "species": [{
                "element": "H",
                "occu": 1
            }],
            "abc": [0.33333, 0.5, 0.397196000059],
            "xyz":
            [1.4092640000074041e-5, -3.2545478636099996, 9.20525164700736],
            "label":
            "H",
            "properties": {
                "SiteTypes": "S1",
                "oss": "-1"
            }
        }, {
            "species": [{
                "element": "H",
                "occu": 1
            }],
            "abc": [0.0, 0.5, 0.496495000084],
            "xyz": [1.409264, -2.440917, 11.506564558996748],
            "label": "H",
            "properties": {
                "SiteTypes": "S1",
                "oss": "-1"
            }
        }, {
            "species": [{
                "element": "H",
                "occu": 1
            }],
            "abc": [0.33333, 0.0, 0.099298999982],
            "xyz": [-1.40924990736, -0.8136308636099999, 2.301312910992839],
            "label":
            "H",
            "properties": {
                "SiteTypes": "S1",
                "oss": "-1"
            }
        }, {
            "species": [{
                "element": "H",
                "occu": 1
            }],
            "abc": [0.0, 0.0, 0.198598000008],
            "xyz": [0.0, 0.0, 4.602625823005404],
            "label": "H",
            "properties": {
                "SiteTypes": "S1",
                "oss": "-1"
            }
        }, {
            "species": [{
                "element": "H",
                "occu": 1
            }],
            "abc": [0.16667, 0.75, 0.297897000033],
            "xyz": [1.40924990736, -4.068203136389999, 6.903938734994795],
            "label":
            "H",
            "properties": {
                "SiteTypes": "S1",
                "oss": "-1"
            }
        }, {
            "species": [{
                "element": "H",
                "occu": 1
            }],
            "abc": [0.33333, 0.0, 0.397196000059],
            "xyz": [-1.40924990736, -0.8136308636099999, 9.20525164700736],
            "label":
            "H",
            "properties": {
                "SiteTypes": "S1",
                "oss": "-1"
            }
        }, {
            "species": [{
                "element": "H",
                "occu": 1
            }],
            "abc": [0.0, 0.0, 0.496495000084],
            "xyz": [0.0, 0.0, 11.506564558996748],
            "label": "H",
            "properties": {
                "SiteTypes": "S1",
                "oss": "-1"
            }
        }, {
            "species": [{
                "element": "H",
                "occu": 1
            }],
            "abc": [0.83333, 0.25, 0.099298999982],
            "xyz": [-2.81851390736, -3.2545478636099996, 2.301312910992839],
            "label":
            "H",
            "properties": {
                "SiteTypes": "S1",
                "oss": "-1"
            }
        }, {
            "species": [{
                "element": "H",
                "occu": 1
            }],
            "abc": [0.5, 0.25, 0.198598000008],
            "xyz": [-1.4092639999999999, -2.440917, 4.602625823005404],
            "label": "H",
            "properties": {
                "SiteTypes": "S1",
                "oss": "-1"
            }
        }, {
            "species": [{
                "element": "H",
                "occu": 1
            }],
            "abc": [0.66667, 0.0, 0.297897000033],
            "xyz": [-2.81854209264, -1.6272861363899997, 6.903938734994795],
            "label":
            "H",
            "properties": {
                "SiteTypes": "S1",
                "oss": "-1"
            }
        }, {
            "species": [{
                "element": "H",
                "occu": 1
            }],
            "abc": [0.83333, 0.25, 0.397196000059],
            "xyz": [-2.81851390736, -3.2545478636099996, 9.20525164700736],
            "label":
            "H",
            "properties": {
                "SiteTypes": "S1",
                "oss": "-1"
            }
        }, {
            "species": [{
                "element": "H",
                "occu": 1
            }],
            "abc": [0.5, 0.25, 0.496495000084],
            "xyz": [-1.4092639999999999, -2.440917, 11.506564558996748],
            "label": "H",
            "properties": {
                "SiteTypes": "S1",
                "oss": "-1"
            }
        }, {
            "species": [{
                "element": "H",
                "occu": 1
            }],
            "abc": [0.83333, 0.75, 0.099298999982],
            "xyz": [-1.40924990736, -5.695464863609999, 2.301312910992839],
            "label":
            "H",
            "properties": {
                "SiteTypes": "S1",
                "oss": "-1"
            }
        }, {
            "species": [{
                "element": "H",
                "occu": 1
            }],
            "abc": [0.5, 0.75, 0.198598000008],
            "xyz": [0.0, -4.881834, 4.602625823005404],
            "label": "H",
            "properties": {
                "SiteTypes": "S1",
                "oss": "-1"
            }
        }, {
            "species": [{
                "element": "H",
                "occu": 1
            }],
            "abc": [0.66667, 0.5, 0.297897000033],
            "xyz": [-1.40927809264, -4.068203136389999, 6.903938734994795],
            "label":
            "H",
            "properties": {
                "SiteTypes": "S1",
                "oss": "-1"
            }
        }, {
            "species": [{
                "element": "H",
                "occu": 1
            }],
            "abc": [0.83333, 0.75, 0.397196000059],
            "xyz": [-1.40924990736, -5.695464863609999, 9.20525164700736],
            "label":
            "H",
            "properties": {
                "SiteTypes": "S1",
                "oss": "-1"
            }
        }, {
            "species": [{
                "element": "H",
                "occu": 1
            }],
            "abc": [0.5, 0.75, 0.496495000084],
            "xyz": [0.0, -4.881834, 11.506564558996748],
            "label": "H",
            "properties": {
                "SiteTypes": "S1",
                "oss": "-1"
            }
        }, {
            "species": [{
                "element": "He",
                "occu": 1
            }],
            "abc": [0.66667, 0.5, 0.546547663253],
            "xyz": [-1.40927809264, -4.068203136389999, 12.666564559009593],
            "label":
            "He",
            "properties": {
                "SiteTypes": "A1",
                "oss": "0"
            }
        }, {
            "species": [{
                "element": "He",
                "occu": 1
            }],
            "abc": [0.66667, 0.0, 0.546547663253],
            "xyz": [-2.81854209264, -1.6272861363899997, 12.666564559009593],
            "label":
            "He",
            "properties": {
                "SiteTypes": "A1",
                "oss": "0"
            }
        }, {
            "species": [{
                "element": "He",
                "occu": 1
            }],
            "abc": [0.16667, 0.75, 0.546547663253],
            "xyz": [1.40924990736, -4.068203136389999, 12.666564559009593],
            "label":
            "He",
            "properties": {
                "SiteTypes": "A1",
                "oss": "2"
            }
        }, {
            "species": [{
                "element": "He",
                "occu": 1
            }],
            "abc": [0.16667, 0.25, 0.546547663253],
            "xyz": [-1.409263999996302e-5, -1.62728613639, 12.666564559009593],
            "label":
            "He",
            "properties": {
                "SiteTypes": "A1",
                "oss": "1"
            }
        }]
    },
    "node_feature": [[0.0, 1.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0],
                     [1.0, 0.0, 0.0]],
    "edges": [[
        0, 2, 3, 1, 1, 2, 3, 1, 0, 2, 3, 1, 0, 1, 2, 0, 0, 3, 1, 0, 3, 2, 1, 1,
        3, 2, 1, 0, 3, 2, 1, 0, 1, 3, 0, 0, 2, 1, 0, 1, 2, 0, 1, 2, 0, 3, 1, 0,
        3, 1, 2, 0, 3, 1, 3, 1, 2, 0, 1, 3, 0, 1, 3, 0, 2, 1, 0, 2, 1, 3, 0, 2,
        1, 2, 1, 3, 0, 3, 0, 1, 0, 1, 3, 2, 1, 2, 1, 0, 2, 1, 0, 1, 3, 2, 3, 0,
        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2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
        2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
        3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
        3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
        3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
        3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3
    ]]
}
+0 −26
Original line number Diff line number Diff line
import os
import json
import numpy as np
from deepchem.feat.material_featurizers.lcnn_featurizer import LCNNFeaturizer
try:
  from pymatgen import Structure
except:
  raise ImportError("This class requires pymatgen to be installed.")


def test_LCNNFeaturizer():
  current_dir = os.path.dirname(os.path.realpath(__file__))
  structure_file = os.path.join(current_dir, 'data',
                                'test_platinum_adsorption.json')
  with open(structure_file, 'r') as f:
    test_data = json.load(f)
    test_data["primitive_cell"]["structure"] = Structure.from_dict(
        test_data["primitive_cell"]["structure"])
    test_data["data point"] = Structure.from_dict(test_data["data point"])

    featuriser = LCNNFeaturizer(**test_data["primitive_cell"])
    data = featuriser._featurize(test_data["data point"])
    assert np.all(data.node_features == np.array(test_data["node_feature"]))
    assert np.all(data.edge_index == test_data["edges"])
    assert data.node_features.shape == (4, 3)
    assert data.edge_index.shape == (2, 456)
+25 −22
Original line number Diff line number Diff line
@@ -8,6 +8,7 @@ from deepchem.molnet.load_function.molnet_loader import TransformerGenerator, _M
from deepchem.feat.material_featurizers.lcnn_featurizer import LCNNFeaturizer
from deepchem.data import Dataset
from typing import List, Optional, Tuple, Union
try:
  from pymatgen import Structure

  PLATINUM_URL = "https://deepchemdata.s3-us-west-1.amazonaws.com/datasets/Platinum_adsorption.tar.gz"
@@ -31,6 +32,8 @@ PRIMITIVE_CELL_INF0 = {
      "ns": 1,
      "na": 1
  }
except:
  raise ImportError("This class requires pymatgen to be installed.")


class _PtAdsorptionLoader(_MolnetLoader):
+3 −1
Original line number Diff line number Diff line
@@ -290,10 +290,12 @@ CGCNNFeaturizer
  :inherited-members:

LCNNFeaturizer
^^^^^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^

.. autoclass:: deepchem.feat.LCNNFeaturizer
  :members:
  :inherited-members:


MaterialCompositionFeaturizer
-----------------------------