Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Dec 8, 2024. It is now read-only.

MRMP changes #112

Merged
merged 96 commits into from
Jun 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
96 commits
Select commit Hold shift + click to select a range
baa57eb
Merge remote-tracking branch 'upstream/develop' into develop
SilviaAmAm Jul 30, 2018
ceb9ef5
Merge remote-tracking branch 'upstream/develop' into develop
SilviaAmAm Aug 15, 2018
d974133
SilviaAmAm Aug 24, 2018
8a3fbf3
Started updating so that model can be trained after its been reloaded
SilviaAmAm Aug 24, 2018
7a2dc7e
SilviaAmAm Aug 25, 2018
b33a537
Merge remote-tracking branch 'upstream/develop' into develop
SilviaAmAm Aug 25, 2018
5525d3b
Updated model so one can predict from xyz and disabled shuffling in t…
SilviaAmAm Aug 26, 2018
bb28c4a
SilviaAmAm Aug 27, 2018
4b29b95
Added some tests to make sure the predictions work
SilviaAmAm Aug 27, 2018
a4dc496
SilviaAmAm Aug 27, 2018
ef5c880
SilviaAmAm Aug 28, 2018
d1e27ad
SilviaAmAm Aug 28, 2018
f3a3e9c
Modified the name of a parameter
SilviaAmAm Aug 29, 2018
c77272e
Made modifications to make te symmetry functions more numerically stable
SilviaAmAm Aug 31, 2018
3db69a3
SilviaAmAm Sep 5, 2018
acf0ee7
SilviaAmAm Sep 5, 2018
49b36c2
SilviaAmAm Sep 6, 2018
75aac67
SilviaAmAm Sep 6, 2018
1f694f8
SilviaAmAm Sep 7, 2018
e5c4787
Attempt at fixing issue #10
SilviaAmAm Sep 11, 2018
fef6fba
another attempt at fixing #10
SilviaAmAm Sep 11, 2018
61fefce
Removed a pointless line
SilviaAmAm Sep 12, 2018
386be84
Merge
SilviaAmAm Sep 13, 2018
4c050f7
set-up
SilviaAmAm Sep 13, 2018
3bdd928
SilviaAmAm Sep 13, 2018
81c9824
Modifications which prevent installation from breaking on BC4
Sep 13, 2018
f4a7424
Merge branch 'kill_gracefully' into develop
SilviaAmAm Sep 13, 2018
4a41f14
Modification to add neural networks to qmlearn
SilviaAmAm Sep 14, 2018
7d7f580
Merge remote-tracking branch 'upstream/develop' into develop_qmlearn
SilviaAmAm Sep 18, 2018
898b640
Fix for issue #8
SilviaAmAm Sep 21, 2018
f77d040
SilviaAmAm Sep 24, 2018
2d5988f
SilviaAmAm Sep 24, 2018
da8b524
SilviaAmAm Sep 25, 2018
227e2b8
SilviaAmAm Sep 25, 2018
250031d
SilviaAmAm Sep 25, 2018
687291b
uncommented examples
SilviaAmAm Sep 25, 2018
4391906
Removed unique_elements in data class
larsbratholm Sep 26, 2018
2fb8d39
Made tensorflow an optional dependency
larsbratholm Sep 26, 2018
819fa71
Made is_numeric non-private and removed legacy code
larsbratholm Sep 26, 2018
20ca689
Added 1d array util function
larsbratholm Sep 27, 2018
9ef8c10
Removed QML check and moved functions from utils to tf_utils
larsbratholm Sep 27, 2018
00a2a7c
Support for linear models (no hidden layers)
larsbratholm Sep 27, 2018
a925ee0
fixed import bug in tf_utils
larsbratholm Sep 27, 2018
c8cf008
Added text to explain that you are scoring on training set
larsbratholm Sep 27, 2018
96713c0
Restructure.
larsbratholm Sep 28, 2018
f313eff
Moved documentation from init to class
larsbratholm Sep 28, 2018
20b78b8
Constant features will now be removed at fit/predict time
larsbratholm Sep 28, 2018
4b785f1
Moved get_batch_size back into utils, since it doesn't depend on tf
larsbratholm Sep 28, 2018
8d62084
Made the NeuralNetwork class compliant with sklearn
larsbratholm Sep 28, 2018
d8447e7
Fixed tests that didn't pass
larsbratholm Sep 28, 2018
a8f6062
Fixed mistake in checks of set_classes() in ARMP
SilviaAmAm Sep 28, 2018
d4d98b6
SilviaAmAm Oct 1, 2018
9539704
Merge remote-tracking branch 'upstream/develop' into develop
SilviaAmAm Oct 1, 2018
2b22aa3
Fixed bug in padding and added examples that give low errors
SilviaAmAm Oct 1, 2018
8f082c5
Attempted fix to make representations single precision
SilviaAmAm Oct 2, 2018
21fd2fd
Hot fix for AtomScaler
SilviaAmAm Oct 2, 2018
f2f7770
Merge pull request #13 from larsbratholm/nn_qmlearn
Oct 2, 2018
999301d
Merge branch 'develop_qmlearn' into develop
SilviaAmAm Oct 2, 2018
9ce72c6
Minor bug fixes
SilviaAmAm Oct 2, 2018
70e8622
SilviaAmAm Oct 2, 2018
89dfda9
Fixed some tests that had failures
SilviaAmAm Oct 3, 2018
908da82
SilviaAmAm Oct 3, 2018
c47ad62
SilviaAmAm Oct 3, 2018
fdc485e
Readded changes to tests
SilviaAmAm Oct 3, 2018
255ea74
Modifications after code review
SilviaAmAm Oct 3, 2018
de3192f
Merge remote-tracking branch 'upstream/develop' into develop
SilviaAmAm Oct 23, 2018
e2feecf
Version with the ACSF basis functions starting at 0.8 A
Dec 11, 2018
162c811
Merge remote-tracking branch 'origin/develop' into develop
SilviaAmAm Dec 11, 2018
c8e2886
Merge remote-tracking branch 'upstream/develop' into develop
SilviaAmAm Dec 11, 2018
9584817
Updated ACSF representations so that the minimum distance at which to…
SilviaAmAm Dec 12, 2018
0639a32
SilviaAmAm Dec 12, 2018
1ee640c
Merge remote-tracking branch 'upstream/develop' into develop
SilviaAmAm Jan 17, 2019
91449e6
SilviaAmAm Jan 30, 2019
4964a7e
SilviaAmAm Jan 31, 2019
0128f24
Fixed bug in the padding of the representation in the ARMP network us…
Feb 5, 2019
e102e2c
Merge branch 'develop' into tolerance_fix
larsbratholm Feb 5, 2019
268b69c
Merge branch 'develop' into tolerance_fix
larsbratholm Feb 5, 2019
ef2895e
Merge remote-tracking branch 'origin/tolerance_fix' into develop
SilviaAmAm Feb 5, 2019
5250ef6
Made a modification to how the Fortran ACSF are generated that helps …
Feb 8, 2019
37e322c
Added a check to make sure there are no NANs in the representations.
Feb 8, 2019
af4d7d5
Small mistake corrected in aglaia
Feb 8, 2019
174efdd
Merge remote-tracking branch 'origin/develop' into develop
SilviaAmAm Feb 11, 2019
35cde4a
Fixed extra space before -lpthread flag
SilviaAmAm Feb 11, 2019
1fc6756
Merge branch 'setup_fix' into develop
SilviaAmAm Feb 11, 2019
55f0934
Removed what I added
Feb 11, 2019
caea93d
Merge branch 'develop' of github.com:SilviaAmAm/qml into develop
SilviaAmAm Feb 11, 2019
f828351
Merge remote-tracking branch 'upstream/develop' into develop
SilviaAmAm Feb 11, 2019
cd0eed5
Merge remote-tracking branch 'upstream/develop' into develop
SilviaAmAm May 24, 2019
1ded384
Implemented MRMP representations from xyz
SilviaAmAm May 24, 2019
6d1b0da
Generate atomic slatm from data
SilviaAmAm Jun 1, 2019
2076a80
Fixed typo
SilviaAmAm Jun 1, 2019
2454d94
Fixed problem with slatm and ARMP
SilviaAmAm Jun 1, 2019
63d58ef
Fixed bug for MRMP tensorboard logger
SilviaAmAm Jun 7, 2019
8c2e4b4
Actually fixed the tensorboard bug for MRMP and added tests to catch …
SilviaAmAm Jun 7, 2019
07ec1b3
Fixed another tensorboard bug
SilviaAmAm Jun 7, 2019
5d13b78
Changed the behaviour of logging to tensorboard in MRMP
SilviaAmAm Jun 7, 2019
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
53 changes: 39 additions & 14 deletions qml/aglaia/aglaia.py
Original file line number Diff line number Diff line change
Expand Up @@ -982,6 +982,22 @@ def _get_classes(self, indices):

return np.asarray(zs, dtype=np.float32)

def _generate_compounds_from_data(self, xyz, classes):
"""
This function generates the compounds from xyz data and nuclear charges.

:param xyz: cartesian coordinates
:type xyz: numpy array of shape (n_samples, n_atoms, 3)
:param classes: classes for atomic decomposition
:type classes: None
:return: array of compound objects
"""
compounds = np.empty(xyz.shape[0], dtype=object)
for i in range(xyz.shape[0]):
compounds[i] = Compound()
compounds[i].set_compounds(xyz=xyz[i], zs=classes[i])
return compounds

def predict(self, x, classes=None):
"""
This function calls the predict function for either ARMP or MRMP.
Expand Down Expand Up @@ -1088,8 +1104,13 @@ def _generate_representations_from_data(self, xyz, classes, method):
:type method: string
:return: numpy array of shape (n_samples, n_features) and None
"""
# TODO implement
raise InputError("Not implemented yet. Use compounds.")

if method != "fortran":
raise NotImplementedError

self.compounds = self._generate_compounds_from_data(xyz, classes)

return self._generate_representations_from_compounds('fortran')

def _generate_representations_from_compounds(self, method):
"""
Expand Down Expand Up @@ -1238,9 +1259,9 @@ def _fit(self, x, y, dy, classes):
opt, c = self.session.run([optimisation_op, cost], feed_dict=feed_dict)
avg_cost += c * batch_x.shape[0] / x_approved.shape[0]

if self.tensorboard:
if self.tensorboard and j == 0:
if i % self.tensorboard_logger_training.store_frequency == 0:
self.tensorboard_logger_training.write_summary(self.session, feed_dict, i, j)
self.tensorboard_logger_training.write_summary(self.session, i, feed_dict=feed_dict)

self.training_cost.append(avg_cost)

Expand Down Expand Up @@ -1642,20 +1663,16 @@ def _generate_representations_from_data(self, xyz, classes, method):
representation = None

if self.representation_name == 'slatm':
# TODO implement
raise InputError("Slatm from data has not been implemented yet. Use Compounds.")
self.compounds = self._generate_compounds_from_data(xyz, classes)
representation, classes = self._generate_representations_from_compounds('fortran')

elif self.representation_name == 'acsf':
if method == 'tf':
representation = self._generate_acsf_tf(xyz, classes)
else:
representation = self._generate_acsf_fortran(xyz, classes)

# Hotfix t make sure the representation is single precision
single_precision_representation = representation.astype(dtype=np.float32)
del representation

return single_precision_representation, classes
return representation, classes

def _generate_acsf_tf(self, xyz, classes):
"""
Expand Down Expand Up @@ -1776,7 +1793,11 @@ def _generate_acsf_fortran(self, xyz, classes):
padded_g = np.zeros((initial_natoms, g.shape[-1]))
padded_g[:g.shape[0], :] = g

representation.append(padded_g)
# Hotfix t make sure the representation is single precision
single_precision_g = padded_g.astype(dtype=np.float32)
del padded_g

representation.append(single_precision_g)

else:

Expand All @@ -1790,7 +1811,10 @@ def _generate_acsf_fortran(self, xyz, classes):
eta3=self.acsf_parameters['eta'],
zeta=self.acsf_parameters['zeta'])

representation.append(g)
single_precision_g = g.astype(dtype=np.float32)
del g

representation.append(single_precision_g)

return np.asarray(representation)

Expand Down Expand Up @@ -2275,7 +2299,8 @@ def _fit_from_scratch(self, x, y, dy, classes):
init = tf.global_variables_initializer()
iterator_init = iterator.make_initializer(dataset, name="dataset_init")

self._build_model_from_xyz(self.n_atoms, element_weights, element_biases)
if self.representation_name == "acsf":
self._build_model_from_xyz(self.n_atoms, element_weights, element_biases)

self.session = tf.Session()

Expand Down
7 changes: 5 additions & 2 deletions qml/aglaia/tf_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,13 @@ def set_store_frequency(self, freq):
def set_summary_writer(self, sess):
self.summary_writer = tf.summary.FileWriter(logdir=self.path, graph=sess.graph)

def write_summary(self, sess, iteration):
def write_summary(self, sess, iteration, feed_dict=None):

self.merged_summary = tf.summary.merge_all()
summary = sess.run(self.merged_summary)
if not isinstance(feed_dict, type(None)):
summary = sess.run(self.merged_summary, feed_dict)
else:
summary = sess.run(self.merged_summary)
self.summary_writer.add_summary(summary, iteration)
self.summary_writer.add_run_metadata(self.run_metadata, 'iteration %d' % (iteration))

Expand Down
4 changes: 2 additions & 2 deletions qml/qmlearn/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -734,8 +734,8 @@ def _padding(self, representation, nuclear_charges):
print("Trying to predict on larger molecules than given by the 'size' parameter at initialization")
raise SystemExit

padded_rep = np.zeros((len(representation), max_n_atoms, representation[0].shape[1]))
padded_zs = np.zeros((len(representation), max_n_atoms))
padded_rep = np.zeros((len(representation), self.size, representation[0].shape[1]))
padded_zs = np.zeros((len(representation), self.size))

for i in range(len(representation)):
n_atoms = representation[i].shape[0]
Expand Down
5 changes: 5 additions & 0 deletions qml/qmlearn/representations.py
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,11 @@ def transform(self, X):
fgenerate_acsf(xyz, charge, self.elements, Rs, Rs, Ts,
eta, eta, zeta, self.cutoff, self.cutoff, n, size)))

# Check to make sure there are no NANs
# if np.any(np.isnan(representations)):
# print("There are NANs in the representations.")
# exit()

data._representations = np.asarray(representations)

return data
Expand Down
19 changes: 19 additions & 0 deletions qml/utils/compound.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,3 +373,22 @@ def read_xyz(self, filename):
self.coordinates[i] = np.asarray(tokens[1:4], dtype=float)

self.natypes = dict([(key, len(value)) for key,value in self.atomtype_indices.items()])

def set_compounds(self, xyz, zs):
"""
Generating the compounds straight from XYZ rather than from the files.

:param xyz: coordinates
:type xyz: np array of shape (n_samples, n_atoms, 3)
:param zs: nuclear charges
:type zs: np array of shape (n_samples, n_atoms)
:return: None
"""

self.natoms = xyz.shape[0]
self.nuclear_charges = zs
self.coordinates = xyz
self.atomtypes = np.unique(zs)

self.name = "Compound"

23 changes: 23 additions & 0 deletions test/test_armp.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,28 @@ def test_fit_3():
estimator = ARMP()
estimator.fit(x=descriptor, y=energies, classes=classes)

def test_fit_4():
"""
This function tests the second way of fitting the descriptor: the data is passed by storing the compounds in the
class.
"""
test_dir = os.path.dirname(os.path.realpath(__file__))

data = np.load(test_dir + "/data/local_slatm_ch4cn_light.npz")
descriptor = data["arr_0"]
classes = data["arr_1"]
energies = data["arr_2"]

estimator = ARMP(tensorboard=True, tensorboard_subdir="./tb_test_4")
estimator.set_representations(representations=descriptor)
estimator.set_classes(classes=classes)
estimator.set_properties(energies)

idx = np.arange(0, 100)
estimator.fit(idx)

shutil.rmtree("./tb_test_4")

def test_score_3():
"""
This function tests that all the scoring functions work.
Expand Down Expand Up @@ -303,6 +325,7 @@ def test_retraining():
test_fit_1()
test_fit_2()
test_fit_3()
test_fit_4()
test_score_3()
test_predict_3()
test_predict_fromxyz()
Expand Down
17 changes: 17 additions & 0 deletions test/test_mrmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,22 @@ def test_fit_3():
estimator = MRMP()
estimator.fit(descriptor, energies)

def test_fit_4():
"""
This function tests a third way of fitting the descriptor:
The data is passed directly to the fit function.
"""
test_dir = os.path.dirname(os.path.realpath(__file__))

data = np.load(test_dir + "/data/CN_isopent_light_UCM.npz")
descriptor = data["arr_0"]
energies = data["arr_1"]

estimator = MRMP(tensorboard=True, tensorboard_subdir="./tb_test_4")
estimator.fit(descriptor, energies)

shutil.rmtree("./tb_test_4")

def test_score():
"""
This function tests that all the scoring functions work.
Expand Down Expand Up @@ -264,6 +280,7 @@ def test_load_external():
test_fit_1()
test_fit_2()
test_fit_3()
test_fit_4()
test_score()
test_load_external()
# test_get_params()