summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ml_exp/compound.py16
-rw-r--r--ml_exp/do_ml.py6
-rw-r--r--ml_exp/representations.py44
3 files changed, 38 insertions, 28 deletions
diff --git a/ml_exp/compound.py b/ml_exp/compound.py
index 4428e9164..6c8525195 100644
--- a/ml_exp/compound.py
+++ b/ml_exp/compound.py
@@ -38,7 +38,7 @@ class Compound:
self.n = None
self.extra = None
self.atoms = None
- self.atoms_nc = None
+ self.nc = None
self.coordinates = None
self.pbe0 = None
self.delta = None
@@ -73,7 +73,7 @@ class Compound:
bohr_ru: if radius units should be in bohr's radius units.
"""
self.cm = coulomb_matrix(self.coordinates,
- self.atoms_nc,
+ self.nc,
size=size,
as_eig=as_eig,
bohr_ru=bohr_ru)
@@ -95,7 +95,7 @@ class Compound:
bohr_ru: if radius units should be in bohr's radius units.
"""
self.ljm = lennard_jones_matrix(self.coordinates,
- self.atoms_nc,
+ self.nc,
diag_value=diag_value,
sigma=sigma,
epsilon=epsilon,
@@ -112,8 +112,8 @@ class Compound:
bohr_ru: if radius units should be in bohr's radius units.
"""
hd = get_helping_data(self.coordinates,
- self.nc,
self.atoms,
+ self.nc,
size=size,
bohr_ru=bohr_ru)
@@ -127,8 +127,8 @@ class Compound:
use_forces: if the use of forces instead of k_cx should be used.
size: compound size.
"""
- self.am = adjacency_matrix(self.fnm,
- self.bonds,
+ self.am = adjacency_matrix(self.bonds_i,
+ self.bonds_k,
self.bonds_f,
use_forces=use_forces,
size=size)
@@ -156,12 +156,12 @@ class Compound:
self.n = np.int32(lines[0])
self.extra = lines[1]
self.atoms = []
- self.atoms_nc = np.empty(self.n, dtype=np.int64)
+ self.nc = np.empty(self.n, dtype=np.int64)
self.coordinates = np.empty((self.n, 3), dtype=np.float64)
for i, atom in enumerate(lines[2:self.n + 2]):
atom_d = atom.split()
self.atoms.append(atom_d[0])
- self.atoms_nc[i] = NUCLEAR_CHARGE[atom_d[0]]
+ self.nc[i] = NUCLEAR_CHARGE[atom_d[0]]
self.coordinates[i] = np.asarray(atom_d[1:4], dtype=np.float64)
diff --git a/ml_exp/do_ml.py b/ml_exp/do_ml.py
index 5054b2b06..5efd13690 100644
--- a/ml_exp/do_ml.py
+++ b/ml_exp/do_ml.py
@@ -176,11 +176,13 @@ def do_ml(db_path='data',
size=size,
as_eig=as_eig,
bohr_ru=bohr_ru)
+ """
if 'AM' in identifiers:
compound.gen_hd(size=size,
bohr_ru=bohr_ru)
compound.gen_am(use_forces=use_forces,
size=size)
+ """
if 'BOB' in identifiers:
compound.gen_bob(size=size)
@@ -189,8 +191,10 @@ def do_ml(db_path='data',
cm_data = np.array([comp.cm for comp in compounds], dtype=np.float64)
if 'LJM' in identifiers:
ljm_data = np.array([comp.ljm for comp in compounds], dtype=np.float64)
+ """
if 'AM' in identifiers:
am_data = np.array([comp.cm for comp in compounds], dtype=np.float64)
+ """
if 'BOB' in identifiers:
bob_data = np.array([comp.bob for comp in compounds], dtype=np.float64)
@@ -218,6 +222,7 @@ def do_ml(db_path='data',
opt=opt,
identifier='LJM',
show_msgs=show_msgs)
+ """
if 'AM' in identifiers:
am_mae, am_tictoc = simple_ml(am_data,
energy_pbe0,
@@ -227,6 +232,7 @@ def do_ml(db_path='data',
opt=opt,
identifier='AM',
show_msgs=show_msgs)
+ """
if 'BOB' in identifiers:
bob_mae, bob_tictoc = simple_ml(bob_data,
energy_pbe0,
diff --git a/ml_exp/representations.py b/ml_exp/representations.py
index 6b5d26bcb..be567d67a 100644
--- a/ml_exp/representations.py
+++ b/ml_exp/representations.py
@@ -167,15 +167,15 @@ size. Arrays are not of the right shape.')
def get_helping_data(coords,
- nc,
atoms,
+ nc,
size=23,
bohr_ru=False):
"""
Creates helping data such as the First Neighbor Matrix for the compound.
coords: compound coordinates.
- nc: nuclear charge data.
atoms: list of atoms.
+ nc: nuclear charge data.
size: compund size.
bohr_ru: if radius units should be in bohr's radius units.
NOTE: Bond distance of carbon to other elements
@@ -203,11 +203,11 @@ size. Arrays are not of the right shape.')
size = n
# Possible bonds.
- cc_bond = sorted(['C', 'C'])
- ch_bond = sorted(['C', 'H'])
- co_bond = sorted(['C', 'O'])
- cn_bond = sorted(['C', 'N'])
- cs_bond = sorted(['C', 'S'])
+ cc_bond = ''.join(sorted(['C', 'C']))
+ ch_bond = ''.join(sorted(['C', 'H']))
+ co_bond = ''.join(sorted(['C', 'O']))
+ cn_bond = ''.join(sorted(['C', 'N']))
+ cs_bond = ''.join(sorted(['C', 'S']))
pos_bonds = {cc_bond: (1.19, 1.54, 1.0), ch_bond: (1.06, 1.12, 1.0),
co_bond: (1.43, 2.15, 0.8), cn_bond: (1.47, 2.19, 1.0),
cs_bond: (1.81, 2.55, 0.7)}
@@ -221,7 +221,7 @@ size. Arrays are not of the right shape.')
for j, xyz_j in enumerate(coords):
# Ignore the diagonal.
if i != j:
- bond = sorted([atoms[i], atoms[j]])
+ bond = ''.join(sorted([atoms[i], atoms[j]]))
if bond in pos_bonds.keys():
r_min = pos_bonds[bond][0]
r_max = pos_bonds[bond][1]
@@ -239,21 +239,25 @@ size. Arrays are not of the right shape.')
return fnm, bonds, bonds_i, bonds_k, bonds_f
-def adjacency_matrix(fnm,
- bonds,
- forces,
+def adjacency_matrix(bonds_i,
+ bonds_k,
+ bonds_f,
use_forces=False,
- size=22):
+ size=23):
"""
Calculates the adjacency matrix given the bond list.
- fnm: first neighbour matrix.
- bonds: list of bonds (tuple of indexes).
- forces: list of forces.
+ bonds: list of bond names.
+ bonds_i: list of bond indexes (tuple of indexes).
+ bonds_k: list of k_cx values.
+ bonds_f: list of force values.
use_forces: if the use of forces instead of k_cx should be used.
size: compund size.
"""
- n = len(bonds)
+ if bonds_i is None:
+ raise ValueError('The helping data hasn\'t been initialized for\
+the current compound.')
+ n = len(bonds_i)
if size < n:
print('Error. Compound size (n) is greater han (size). Using (n)\
instead of (size).')
@@ -261,15 +265,15 @@ def adjacency_matrix(fnm,
am = np.zeros((size, size), dtype=np.float64)
- for i, bond_i in enumerate(bonds):
- for j, bond_j in enumerate(bonds):
+ for i, bond_i in enumerate(bonds_i):
+ for j, bond_j in enumerate(bonds_i):
# Ignore the diagonal.
if i != j:
if (bond_i[0] in bond_j) or (bond_i[1] in bond_j):
if use_forces:
- am[i, j] = np.dot(forces[i], forces[j])
+ am[i, j] = np.dot(bonds_f[i], bonds_f[j])
else:
- am[i, j] = fnm[bond_i[0], bond_i[1]]
+ am[i, j] = bonds_k[i]
return am