Commit d6a38486 authored by VIGNESHinZONE's avatar VIGNESHinZONE
Browse files

Removed few unnecessary functions

parent 0655cbe1
Loading
Loading
Loading
Loading
+46 −88
Original line number Diff line number Diff line
@@ -27,7 +27,6 @@ class LCNNFeaturizer(Featurizer):

  Examples
  ----------
      
  The input format for primitive cell Template is stored in a file named

  [comment]
@@ -218,7 +217,6 @@ class SiteEnvironment(object):
        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]
@@ -305,29 +303,6 @@ class SiteEnvironment(object):
        n += 1
    return G

  def __repr__(self):
    s = '<' + self.sitetypes[0] + \
        '|%i active neighbors' % (len([s for s in self.sitetypes if 'A' in s]) - 1) + \
        '|%i spectator neighbors' % len([s for s in self.sitetypes if 'S' in s]) + \
        '|%4.2f Ang Cutoff' % self.cutoff + '| %i permutations>' % len(self.permutations)
    return s

  def __eq__(self, o):
    """
    Local environment comparison is done by comparing represented site
    """
    if not isinstance(o, SiteEnvironment):
      raise ValueError
    return self.sitetypes[0] == o.sitetypes[0]

  def __ne__(self, o):
    """
    Local environment comparison is done by comparing represented site
    """
    if isinstance(o, SiteEnvironment):
      raise ValueError
    return not self.__eq__(o)

  def GetMapping(self, env, path=None):
    """
    Returns mapping of sites from input to this object
@@ -339,7 +314,8 @@ class SiteEnvironment(object):
    performed to make sure it is a match. NetworkX is used for portability.

    Parameters
    ----------
    ----------any discussion during Thursday 8 Oct. Lect . ok

    env : dictionary that contains information of local environment of a
        site in datum. See _GetSiteEnvironments defintion in the class
        SiteEnvironments for what this variable should be.
@@ -442,16 +418,6 @@ class SiteEnvironments(object):
    self.pbc = pbc
    self.cutoff = cutoff

  def __repr__(self):
    s = '<%i active sites' % (self.na) + '|%i spectator sites' % (self.ns) + '>'
    return s

  def __getitem__(self, el):
    """
    Returns a site environment
    """
    return self.site_envs[el]

  def ReadDatum(self, text, cutoff_factor=1.1):
    """
    Load structure data and return neighbor information
@@ -682,11 +648,3 @@ class SiteEnvironments(object):
      }
      site_envs.append(site_env)
    return site_envs


def _chunks(length, number):
  """
  Yield successive n-sized chunks from length.
  """
  for i in range(0, len(length), number):
    yield length[i:i + number]
+38 −1
Original line number Diff line number Diff line
@@ -46,11 +46,48 @@ structure = """-4.22779200e+00 -2.44091700e+00 0.00000000e+00
 0.166670000000  0.750000000000  0.546547663253 A1 2
 0.166670000000  0.250000000000  0.546547663253 A1 1
"""
check1 = np.array([[0., 1., 0.],
                   [0., 1., 0.],
                   [0., 0., 1.],
                   [1., 0., 0.]])

check2 = np.array([[[[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, 2, 0, 1, 0, 1, 2, 3, 1, 3, 1, 0, 3, 1, 0, 1, 2, 3, 2]],

                    [[1, 3, 2, 0, 0, 3, 2, 0, 1, 3, 2, 0, 1, 0, 3, 1, 1, 2, 0],
                    [1, 2, 3, 0, 0, 2, 3, 0, 1, 2, 3, 0, 1, 0, 2, 1, 1, 3, 0],
                    [1, 0, 3, 1, 0, 3, 1, 2, 0, 1, 2, 0, 3, 1, 2, 0, 2, 0, 3],
                    [1, 0, 2, 1, 0, 2, 1, 3, 0, 1, 3, 0, 2, 1, 3, 0, 3, 0, 2],
                    [1, 2, 1, 0, 1, 0, 2, 3, 0, 3, 0, 1, 3, 0, 1, 0, 2, 3, 2],
                    [1, 3, 1, 0, 1, 0, 3, 2, 0, 2, 0, 1, 2, 0, 1, 0, 3, 2, 3]],

                    [[2, 1, 0, 3, 3, 1, 0, 3, 2, 1, 0, 3, 2, 3, 1, 2, 2, 0, 3],
                    [2, 0, 1, 3, 3, 0, 1, 3, 2, 0, 1, 3, 2, 3, 0, 2, 2, 1, 3],
                    [2, 3, 1, 2, 3, 1, 2, 0, 3, 2, 0, 3, 1, 2, 0, 3, 0, 3, 1],
                    [2, 3, 0, 2, 3, 0, 2, 1, 3, 2, 1, 3, 0, 2, 1, 3, 1, 3, 0],
                    [2, 0, 2, 3, 2, 3, 0, 1, 3, 1, 3, 2, 1, 3, 2, 3, 0, 1, 0],
                    [2, 1, 2, 3, 2, 3, 1, 0, 3, 0, 3, 2, 0, 3, 2, 3, 1, 0, 1]],

                    [[3, 0, 1, 2, 2, 0, 1, 2, 3, 0, 1, 2, 3, 2, 0, 3, 3, 1, 2],
                    [3, 1, 0, 2, 2, 1, 0, 2, 3, 1, 0, 2, 3, 2, 1, 3, 3, 0, 2],
                    [3, 2, 0, 3, 2, 0, 3, 1, 2, 3, 1, 2, 0, 3, 1, 2, 1, 2, 0],
                    [3, 2, 1, 3, 2, 1, 3, 0, 2, 3, 0, 2, 1, 3, 0, 2, 0, 2, 1],
                    [3, 1, 3, 2, 3, 2, 1, 0, 2, 0, 2, 3, 0, 2, 3, 2, 1, 0, 1],
                    [3, 0, 3, 2, 3, 2, 0, 1, 2, 1, 2, 3, 1, 2, 3, 2, 0, 1, 0]]]])


def test_LCNNFeaturizer():
    featuriser = LCNNFeaturizer(np.around(6.00), template)
    data = featuriser._featurize(structure)
    assert np.all(data['X_Sites'] == check1)
    assert np.all(data['X_NSs'] == check2)
    assert data['X_Sites'].shape == (4, 3)
    assert data['X_NSs'].shape == (1, 4, 6, 19)


if __name__ == "__main__":
    test_LCNNFeaturizer()