diff options
author | David Luevano Alvarado <55825613+luevano@users.noreply.github.com> | 2020-02-23 21:03:39 -0700 |
---|---|---|
committer | David Luevano Alvarado <55825613+luevano@users.noreply.github.com> | 2020-02-23 21:03:39 -0700 |
commit | db47ff8606b14e4cdddc0e317972c3515b9c788b (patch) | |
tree | 8f3d23c64a82a5f580c51fdd55e2ae070957e83b | |
parent | 85198178482767d2831ddf3762e5e6eeafa990bd (diff) |
Fix adj matrix issue with cc bonds)
-rw-r--r-- | ml_exp/__main__.py | 11 | ||||
-rw-r--r-- | ml_exp/compound.py | 6 | ||||
-rw-r--r-- | ml_exp/representations.py | 29 |
3 files changed, 26 insertions, 20 deletions
diff --git a/ml_exp/__main__.py b/ml_exp/__main__.py index 17119623e..124ce8cd9 100644 --- a/ml_exp/__main__.py +++ b/ml_exp/__main__.py @@ -25,6 +25,11 @@ from ml_exp.compound import Compound if __name__ == '__main__': print('Initialize test') - test = [] - for i in range(1, 10): - test.append(Compound(f'/home/luevano/py/ml_exp/data/qm7/000{i}.xyz')) + mol_name = '/home/luevano/py/ml_exp/data/qm7/0004.xyz' + mol = Compound(mol_name) + mol.gen_cm(size=1, as_eig=False) + mol.gen_ljm(size=1, as_eig=False) + mol.gen_am(size=1) + + print(mol.n, mol.atoms, mol.atoms_nc) + print(mol.am) diff --git a/ml_exp/compound.py b/ml_exp/compound.py index d4dc9b7c0..d499e6b83 100644 --- a/ml_exp/compound.py +++ b/ml_exp/compound.py @@ -39,7 +39,8 @@ class Compound: self.atoms = None self.atoms_nc = None self.coordinates = None - self.energy = None + self.pbe0 = None + self.delta = None self.cm = None self.ljm = None @@ -91,8 +92,8 @@ class Compound: bohr_ru=bohr_ru) def gen_am(self, - use_forces=False, size=23, + use_forces=False, bohr_ru=False): """ Generate the Adjacency Matrix for the compund. @@ -104,6 +105,7 @@ class Compound: fnm, bonds, forces = first_neighbor_matrix(self.coordinates, self.atoms_nc, self.atoms, + size=size, use_forces=use_forces, bohr_ru=bohr_ru) diff --git a/ml_exp/representations.py b/ml_exp/representations.py index 796d15f98..11c30dfd2 100644 --- a/ml_exp/representations.py +++ b/ml_exp/representations.py @@ -39,7 +39,7 @@ def coulomb_matrix(coords, if bohr_ru: cr = 0.52917721067 else: - cr = 1 + cr = 1.0 n = coords.shape[0] @@ -106,7 +106,7 @@ def lennard_jones_matrix(coords, if bohr_ru: cr = 0.52917721067 else: - cr = 1 + cr = 1.0 n = coords.shape[0] @@ -168,6 +168,7 @@ def lennard_jones_matrix(coords, def first_neighbor_matrix(coords, nc, atoms, + size=23, use_forces=False, bohr_ru=False): """ @@ -179,7 +180,7 @@ def first_neighbor_matrix(coords, bohr_ru: if radius units should be in bohr's radius units. NOTE: Bond distance of carbon to other elements are (for atoms present in the qm7 dataset): - C: 1.20 - 1.53 A + C: 1.20 - 1.54 A (Edited to 1.19 - 1.54 A) H: 1.06 - 1.12 A O: 1.43 - 2.15 A N: 1.47 - 2.10 A @@ -188,7 +189,7 @@ def first_neighbor_matrix(coords, if bohr_ru: cr = 0.52917721067 else: - cr = 1 + cr = 1.0 n = coords.shape[0] @@ -196,6 +197,11 @@ def first_neighbor_matrix(coords, raise ValueError('Compound size is different than the nuclear charge\ size. Arrays are not of the right shape.') + if size < n: + print('Error. Compound size (n) is greater han (size). Using (n)', + 'instead of (size).') + size = n + # Possible bonds. cc_bond = sorted(['C', 'C']) ch_bond = sorted(['C', 'H']) @@ -203,16 +209,12 @@ def first_neighbor_matrix(coords, cn_bond = sorted(['C', 'N']) cs_bond = sorted(['C', 'S']) - if use_forces: - fnm = np.zeros((n, n), dtype=float) - else: - fnm = np.zeros((n, n), dtype=int) + fnm = np.zeros((size, size), dtype=float) bonds = [] forces = [] for i, xyz_i in enumerate(coords): for j, xyz_j in enumerate(coords): - # Ignore the diagonal. if i != j: bond = sorted([atoms[i], atoms[j]]) @@ -220,7 +222,7 @@ def first_neighbor_matrix(coords, r = np.linalg.norm(rv)/cr # Check for each type of bond. - if (cc_bond == bond) and (r >= 1.20 and r <= 1.53): + if (cc_bond == bond) and (r >= 1.19 and r <= 1.54): fnm[i, j] = 1.0 if j > i: bonds.append((i, j)) @@ -257,7 +259,7 @@ def first_neighbor_matrix(coords, def adjacency_matrix(fnm, bonds, forces, - size=23): + size=22): """ Calculates the adjacency matrix given the bond list. fnm: first neighbour matrix. @@ -272,10 +274,7 @@ def adjacency_matrix(fnm, instead of (size).') size = n - if forces: - am = np.zeros((size, size), dtype=float) - else: - am = np.zeros((size, size), dtype=int) + am = np.zeros((size, size), dtype=float) for i, bond_i in enumerate(bonds): for j, bond_j in enumerate(bonds): |