Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Training on energy labels #128

Merged
merged 126 commits into from
May 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
126 commits
Select commit Hold shift + click to select a range
28d724d
start energy gp
jonpvandermause Sep 29, 2019
fb76ae1
by default, add all envs of a structure to the training set
jonpvandermause Sep 29, 2019
1939742
implement get_kernel_vector
jonpvandermause Sep 30, 2019
2b0f351
add energy kernel
jonpvandermause Sep 30, 2019
443ae51
add get_labels method to struc
jonpvandermause Sep 30, 2019
f3941dc
implement ky block
jonpvandermause Sep 30, 2019
4b8c7d3
fix index in gp algebra
jonpvandermause Sep 30, 2019
faa31fa
edit energy gp test
jonpvandermause Sep 30, 2019
b01039a
fix index error in energy_gp; default forces to none in struc
jonpvandermause Sep 30, 2019
9f46bcc
add fractional corrections to mc energy kernel
jonpvandermause Sep 30, 2019
06496d8
switch energy_force to force_energy to match input order
jonpvandermause Sep 30, 2019
7d32db8
implement ky_mat
jonpvandermause Sep 30, 2019
e73703b
change kernel_ef to kernel_fe
jonpvandermause Sep 30, 2019
5b8314f
implement noise matrix
jonpvandermause Sep 30, 2019
54ed030
add noise matrix to covariance matrix
jonpvandermause Sep 30, 2019
d63c92a
check gp test
jonpvandermause Sep 30, 2019
d7cd4a7
add ky test
jonpvandermause Sep 30, 2019
323588f
make ky test harder
jonpvandermause Sep 30, 2019
8682b05
implement set_L_alpha
jonpvandermause Sep 30, 2019
b8b32d6
add sweep option to env
jonpvandermause Sep 30, 2019
bef49fd
get np training labels from dict
jonpvandermause Sep 30, 2019
e551a61
add sweep as an input to env
jonpvandermause Sep 30, 2019
18cf26a
add sweep option to update db
jonpvandermause Sep 30, 2019
4e30ca0
fix numba seg fault
jonpvandermause Sep 30, 2019
351faa5
more seg fault fixes
jonpvandermause Sep 30, 2019
e661c66
account for case where energy is 0
jonpvandermause Sep 30, 2019
edd2f4c
remove debug print statements
jonpvandermause Sep 30, 2019
d515e17
fix bugs in gp algebra
jonpvandermause Oct 1, 2019
494a7cd
make energy noise a separate hyperparameter
jonpvandermause Oct 7, 2019
ee5854c
update energy test
jonpvandermause Oct 7, 2019
23d427c
add force energy kernel to mgp
jonpvandermause Oct 7, 2019
55988fd
remove training data from mgp
jonpvandermause Oct 7, 2019
5176ca0
remove training data again
jonpvandermause Oct 7, 2019
cea7455
correct typo
jonpvandermause Oct 7, 2019
3990949
allow variance to be computed for global energies
jonpvandermause Oct 16, 2019
c85c4a9
fix merge conflicits
jonpvandermause Dec 13, 2019
a892811
start fixing tests
jonpvandermause Dec 13, 2019
3a92a68
try flare io fix
jonpvandermause Dec 13, 2019
7854012
fix otf_parser
jonpvandermause Dec 13, 2019
aace8cb
pep8 fix
jonpvandermause Dec 13, 2019
ac2a8bb
more test fixes
jonpvandermause Dec 14, 2019
7238256
fix mc_simple tets
jonpvandermause Dec 14, 2019
357e500
fix struc constructor
jonpvandermause Dec 14, 2019
67b5d72
correct fractional factors in mc energy kernels
jonpvandermause Dec 15, 2019
bb1fe35
correct fractional factors in single element energy kernels
jonpvandermause Dec 15, 2019
35fd448
switch force/energy to energy/force in energy_gp.py
jonpvandermause Dec 15, 2019
92a5ac4
remove gp assertion
jonpvandermause Dec 15, 2019
24495b1
make par_en compatible with gp_energy
jonpvandermause Dec 15, 2019
2eb9597
improve predict; remove training_data condition from mgp
jonpvandermause Dec 15, 2019
164d191
fix mgp error
jonpvandermause Dec 15, 2019
d75d1ee
add training label condition to mgp
jonpvandermause Dec 16, 2019
0e1a707
set struc forces and stds in predict; begin cleaning up output file
jonpvandermause Dec 17, 2019
a61e88e
reinstate call to write_xyz
jonpvandermause Dec 17, 2019
c7d4e9f
reinstate header definition
jonpvandermause Dec 17, 2019
1f92c40
reinstate arbitrary print statements
jonpvandermause Dec 17, 2019
954c2ff
make logger compatible with new ase release
jonpvandermause Dec 17, 2019
ede9a6f
merge development branch
jonpvandermause May 7, 2020
fb4c4e5
merge tip of development
jonpvandermause May 7, 2020
f8f4852
Update .travis.yml
jonpvandermause May 7, 2020
b49cd41
Update .travis.yml
jonpvandermause May 7, 2020
217e9bb
fix energy gp import
jonpvandermause May 7, 2020
61fbb8a
Merge branch 'feature/jon/gp-energy' of https://github.com/mir-group/…
jonpvandermause May 7, 2020
5c75937
address test_gp errors
jonpvandermause May 7, 2020
1a7d116
address test_kernel errors
jonpvandermause May 8, 2020
0a61d9f
fix test_struc errors
jonpvandermause May 8, 2020
1171862
remove test files
jonpvandermause May 8, 2020
9999f64
address test_predict errors
jonpvandermause May 8, 2020
d68defb
try addressing cp2k error
jonpvandermause May 8, 2020
edb07f7
reinstate cp2k executable
jonpvandermause May 8, 2020
ac32593
add global training structures to gp algebra
jonpvandermause May 8, 2020
6fca62b
Merge branch 'feature/jon/gp-energy' of https://github.com/mir-group/…
jonpvandermause May 8, 2020
2fa3991
get rid of unused/untested methods
jonpvandermause May 8, 2020
2636392
remove unused import from energy gp
jonpvandermause May 8, 2020
f922f84
add training structures and energy label attributes to the gp
jonpvandermause May 8, 2020
cc03625
update update_db to include energy labels
jonpvandermause May 8, 2020
75fd38d
minor gp_algebra edits
jonpvandermause May 8, 2020
adf38b2
address bare exception in gp algebra
jonpvandermause May 8, 2020
7665aa5
add energy noise attribute to gp
jonpvandermause May 8, 2020
6b67b76
change get_ky_mat to get_force_block
jonpvandermause May 8, 2020
339ce50
clean up gp algebra tests
jonpvandermause May 8, 2020
8c52fc4
add headings to gp_algebra; clean up gp
jonpvandermause May 8, 2020
dffd56a
change ky_pack to force_block_pack
jonpvandermause May 8, 2020
39c65e8
add parallel matrix helper function
jonpvandermause May 8, 2020
4e54897
sketch out energy block methods
jonpvandermause May 8, 2020
085ded8
implement energy_block_pack and force_energy_block_pack methods
jonpvandermause May 8, 2020
14c98a9
implement energy_block method
jonpvandermause May 8, 2020
daae235
give partition methods descriptive names
jonpvandermause May 8, 2020
5453f37
add force/energy partition method; fix mgp import
jonpvandermause May 8, 2020
4349301
implement force/energy block
jonpvandermause May 8, 2020
64acafc
implement full covariance matrix
jonpvandermause May 8, 2020
14439bf
start energy block tesrt
jonpvandermause May 9, 2020
1217016
add test of energy block; add appropriate fractional factors to sephy…
jonpvandermause May 9, 2020
c175b8f
more missing fractional factors in energy kernels
jonpvandermause May 9, 2020
2b0c9b1
start force/energy block test; fix unit tests
jonpvandermause May 9, 2020
5a0ce89
finish force/energy block test
jonpvandermause May 9, 2020
05bc2ba
correct Ky_mat method; begin test
jonpvandermause May 9, 2020
b3f73b1
complete ky_mat test; get rid of redundant tests
jonpvandermause May 9, 2020
1833176
add parallel vector construction method
jonpvandermause May 9, 2020
097d2a2
fix input order
jonpvandermause May 9, 2020
eaf7e96
fix hanging unit test
jonpvandermause May 9, 2020
5cca7ea
unit test en_kern_vec
jonpvandermause May 9, 2020
85a70e1
rename vector unit
jonpvandermause May 9, 2020
4fd96bc
implement force_energy vector
jonpvandermause May 9, 2020
ed2df43
make kernel vector names more logical
jonpvandermause May 9, 2020
6d823cb
test all 4 vector methods
jonpvandermause May 9, 2020
f47610b
implement kernel vector
jonpvandermause May 10, 2020
3555eab
try correcting unit tests
jonpvandermause May 10, 2020
3ca3d96
try fixing tests again
jonpvandermause May 10, 2020
268c777
unit test en_kern_vec
jonpvandermause May 10, 2020
b4614bf
implement and unit test energy and force block updates
jonpvandermause May 11, 2020
c65200b
update partition_update
jonpvandermause May 11, 2020
b8e9834
update force energy block
jonpvandermause May 11, 2020
f5c3944
implement update_ky; remove redundant tests
jonpvandermause May 12, 2020
92bdd5e
fix update_L_alpha
jonpvandermause May 12, 2020
d8c50e0
minor mgp_en changes
jonpvandermause May 12, 2020
1a48327
lint mgp_en
jonpvandermause May 12, 2020
df35626
add energy label to fake gp
jonpvandermause May 13, 2020
f1d3e8e
add energies to test gps; update gp.py to account for energies
jonpvandermause May 13, 2020
8ea0e58
make mgp_en compatible with energy labels
jonpvandermause May 13, 2020
36aedee
use force labels only in mgp_ff unit test
jonpvandermause May 13, 2020
408061b
remove old files
jonpvandermause May 13, 2020
1af8b54
Merge branch 'development' into feature/jon/gp-energy
jonpvandermause May 13, 2020
7a46c98
relax map test
jonpvandermause May 13, 2020
e67d6b6
fix failing unit test
jonpvandermause May 13, 2020
3066c86
add optional sweep argument to update_db
jonpvandermause May 14, 2020
734e959
update structure and energy list in gp instantiation
jonpvandermause May 14, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions flare/dft_interface/qe_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,18 @@ def run_dft_en_par(dft_input, structure, dft_loc, n_cpus):
return forces, energy


def run_dft_en_npool(qe_input, structure, dft_loc, npool):
run_qe_path = qe_input
edit_dft_input_positions(run_qe_path, structure)
qe_command = \
'mpirun {0} -npool {1} < {2} > {3}'.format(dft_loc, npool, run_qe_path,
'pwscf.out')
call(qe_command, shell=True)
forces, energy = parse_dft_forces_and_energy('pwscf.out')

return forces, energy


def parse_dft_input(dft_input: str):
""" parse the input to get information of atomic configuration

Expand Down
55 changes: 30 additions & 25 deletions flare/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,25 @@


class AtomicEnvironment:
"""
Contains information about the local environment of an atom, including
arrays of pair and triplet distances and the chemical species of atoms
in the environment.
"""Contains information about the local environment of an atom,
including arrays of pair and triplet distances and the chemical
species of atoms in the environment.

:param structure: Structure of atoms.
:type structure: struc.Structure
:param atom: Index of the atom in the structure.
:type atom: int
:param cutoffs: 2- and 3-body cutoff radii. 2-body if one cutoff is
given, 2+3-body if two are passed.
given, 2+3-body if two are passed.
:type cutoffs: np.ndarray
"""

def __init__(self, structure: Structure, atom: int, cutoffs):
def __init__(self, structure: Structure, atom: int, cutoffs, sweep=1):
self.structure = structure
self.positions = structure.wrapped_positions
self.cell = structure.cell
self.species = structure.coded_species
self.sweep_array = np.arange(-sweep, sweep+1, 1)

self.atom = atom
self.ctype = structure.coded_species[atom]
Expand All @@ -40,31 +40,33 @@ def compute_env(self):
# get 2-body arrays
bond_array_2, bond_positions_2, etypes = \
get_2_body_arrays(self.positions, self.atom, self.cell,
self.cutoffs[0], self.species)
self.cutoffs[0], self.species, self.sweep_array)
self.bond_array_2 = bond_array_2
self.etypes = etypes

# if 2 cutoffs are given, create 3-body arrays
if len(self.cutoffs) > 1:
bond_array_3, cross_bond_inds, cross_bond_dists, triplet_counts = \
get_3_body_arrays(bond_array_2, bond_positions_2, self.cutoffs[1])
get_3_body_arrays(bond_array_2, bond_positions_2,
self.cutoffs[1])
self.bond_array_3 = bond_array_3
self.cross_bond_inds = cross_bond_inds
self.cross_bond_dists = cross_bond_dists
self.triplet_counts = triplet_counts

# if 3 cutoffs are given, create many-body arrays
if len(self.cutoffs) > 2:
self.bond_array_mb, self.neigh_dists_mb, self.num_neighs_mb, self.etype_mb, \
self.bond_array_mb_etypes = get_m_body_arrays(
self.positions, self.atom, self.cell, self.cutoffs[2], self.species)
self.bond_array_mb, self.neigh_dists_mb, self.num_neighs_mb, \
self.etype_mb, self.bond_array_mb_etypes = \
get_m_body_arrays(self.positions, self.atom,
self.cell, self.cutoffs[2],
self.species, self.sweep_array)
else:
self.bond_array_mb = None
self.neigh_dists_mb = None
self.num_neighs_mb = None
self.etype_mb = None


def as_dict(self):
"""
Returns Atomic Environment object as a dictionary for serialization
Expand Down Expand Up @@ -123,7 +125,8 @@ def __str__(self):


@njit
def get_2_body_arrays(positions, atom: int, cell, cutoff_2: float, species):
def get_2_body_arrays(positions: np.ndarray, atom: int, cell: np.ndarray,
cutoff_2: float, species: np.ndarray, sweep: np.ndarray):
"""Returns distances, coordinates, and species of atoms in the 2-body
local environment. This method is implemented outside the AtomicEnvironment
class to allow for njit acceleration with Numba.
Expand Down Expand Up @@ -154,12 +157,13 @@ class to allow for njit acceleration with Numba.
their atomic number.
:rtype: np.ndarray, np.ndarray, np.ndarray
"""

noa = len(positions)
pos_atom = positions[atom]
coords = np.zeros((noa, 3, 27), dtype=np.float64)
dists = np.zeros((noa, 27), dtype=np.float64)
super_count = sweep.shape[0]**3
coords = np.zeros((noa, 3, super_count))
dists = np.zeros((noa, super_count))
cutoff_count = 0
super_sweep = np.array([-1, 0, 1], dtype=np.float64)

vec1 = cell[0]
vec2 = cell[1]
Expand All @@ -169,9 +173,9 @@ class to allow for njit acceleration with Numba.
for n in range(noa):
diff_curr = positions[n] - pos_atom
im_count = 0
for s1 in super_sweep:
for s2 in super_sweep:
for s3 in super_sweep:
for s1 in sweep:
for s2 in sweep:
for s3 in sweep:
im = diff_curr + s1 * vec1 + s2 * vec2 + s3 * vec3
dist = sqrt(im[0] * im[0] + im[1] * im[1] + im[2] * im[2])
if (dist < cutoff_2) and (dist != 0):
Expand All @@ -188,7 +192,7 @@ class to allow for njit acceleration with Numba.

for m in range(noa):
spec_curr = species[m]
for n in range(27):
for n in range(super_count):
dist_curr = dists[m, n]
if (dist_curr < cutoff_2) and (dist_curr != 0):
coord = coords[m, :, n]
Expand Down Expand Up @@ -371,7 +375,8 @@ def get_3_body_arrays(bond_array_2, bond_positions_2, cutoff_3: float):


@njit
def get_m_body_arrays(positions, atom: int, cell, cutoff_mb: float, species):
def get_m_body_arrays(positions, atom: int, cell, cutoff_mb: float, species,
sweep: np.ndarray):
"""Returns distances, and species of atoms in the many-body
local environment, and returns distances and numbers of neighbours for atoms in the one
many-body local environment. This method is implemented outside the AtomicEnvironment
Expand Down Expand Up @@ -421,23 +426,23 @@ class to allow for njit acceleration with Numba.
neighbouring_etypes = []
max_neighbours = 0
for m in bond_inds:
neighbour_bond_array_2, ___, etypes_mb = get_2_body_arrays(positions, m, cell,
cutoff_mb, species)
neighbour_bond_array_2, ___, etypes_mb = \
get_2_body_arrays(positions, m, cell, cutoff_mb, species, sweep)
neighbouring_dists.append(neighbour_bond_array_2[:, 0])
neighbouring_etypes.append(etypes_mb)
if len(neighbour_bond_array_2[:, 0]) > max_neighbours:
max_neighbours = len(neighbour_bond_array_2[:, 0])

# Transform list of distances into Numpy array
neigh_dists_mb = np.zeros((len(bond_inds), max_neighbours), dtype=np.float64)
neigh_dists_mb = \
np.zeros((len(bond_inds), max_neighbours), dtype=np.float64)
num_neighs_mb = np.zeros(len(bond_inds), dtype=np.int8)
etypes_mb_array = np.zeros((len(bond_inds), max_neighbours), dtype=np.int8)
for i in range(len(bond_inds)):
num_neighs_mb[i] = len(neighbouring_dists[i])
neigh_dists_mb[i, :num_neighs_mb[i]] = neighbouring_dists[i]
etypes_mb_array[i, :num_neighs_mb[i]] = neighbouring_etypes[i]


return bond_array_mb, neigh_dists_mb, num_neighs_mb, etypes_mb_array, etypes


Expand Down
3 changes: 2 additions & 1 deletion flare/flare_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ def md_trajectory_from_file(filename: str):
"""
with open(filename, 'r') as f:
structure_list = load(f)
structures = [Structure.from_dict(dictionary) for dictionary in structure_list]
structures = \
[Structure.from_dict(dictionary) for dictionary in structure_list]
return structures
Loading