Skip to content

Commit 89a53ae

Browse files
WIP: add AFLOW, prereqs and a Dockerfile that tests it
1 parent 084de56 commit 89a53ae

File tree

5 files changed

+193
-1
lines changed

5 files changed

+193
-1
lines changed

docker/install/Dockerfile

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ RUN ${PIP} install markupsafe==2.0.1
3939
RUN ${PIP} install Jinja2==2.11.3
4040
RUN ${PIP} install edn_format==0.7.5
4141
RUN ${PIP} install kim-edn==1.3.1
42-
RUN ${PIP} install kim-property==2.4.0
42+
RUN ${PIP} install kim-property==2.5.7
4343
RUN ${PIP} install kim-query==3.0.0
4444
RUN ${PIP} install simplejson==3.17.2
4545
RUN ${PIP} install numpy==1.19.5
@@ -48,6 +48,7 @@ RUN ${PIP} install matplotlib==3.7.1
4848
RUN ${PIP} install pymongo==3.11.3
4949
RUN ${PIP} install montydb==2.1.1
5050
RUN ${PIP} install pybind11==2.6.2
51+
RUN ${PIP} install spglib==2.1.0
5152

5253
#########################################
5354
## MD++
@@ -159,3 +160,19 @@ RUN cd ${PACKAGE_DIR} \
159160
&& rm convergence.txz \
160161
&& cd convergence \
161162
&& ${PIP} install .
163+
164+
#########################################
165+
## AFLOW
166+
#########################################
167+
ARG AFLOW_VER=3.2.14
168+
ARG AFLOW_PACKAGE=aflow.${AFLOW_VER}
169+
ARG AFLOW_ARCHIVE_TXZ=${AFLOW_PACKAGE}.tar.xz
170+
RUN cd ${PACKAGE_DIR} \
171+
&& wget -q http://materials.duke.edu/AFLOW/${AFLOW_ARCHIVE_TXZ} \
172+
&& tar xJf ${AFLOW_ARCHIVE_TXZ} \
173+
&& rm ${AFLOW_ARCHIVE_TXZ} \
174+
&& cd ${AFLOW_PACKAGE} \
175+
&& make -j2 \
176+
&& cp aflow aflow_data /usr/local/bin \
177+
&& cd ${PACKAGE_DIR} \
178+
&& rm -r ${AFLOW_PACKAGE}

docker/test/Dockerfile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
ARG IMAGE_MINIMAL
2+
3+
FROM ${IMAGE_MINIMAL}
4+
5+
COPY test_scripts_and_data test_scripts_and_data
6+
7+
ENV LD_LIBRARY_PATH :/usr/local/lib
8+
9+
# for now filenames are hardcoded, including a string literal in compare_dbs.py
10+
RUN /bin/bash -c 'cd test_scripts_and_data && bash set_up_and_run_equilibriumcrystalstructure_sample.sh && python compare_dbs.py'
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
from montydb import MontyClient
2+
import numpy as np
3+
import json
4+
5+
def compare_db_to_reference(reference_json_path: str, test_db_path: str, float_fractional_tolerance: float = 0.01):
6+
"""
7+
Compare a montydb generated by tests in the KDP to a reference json file.
8+
The test DB is queried using MontyClient, while the reference json is accessed directly.
9+
The reference json contains data types that are used to determine comparison tolerances.
10+
11+
Args:
12+
reference_json_path:
13+
Path to reference JSON file. This should be copied from /pipeline/db/db/data.json in the KDP
14+
test_db_path:
15+
Path to entire db directory generated in /pipeline/db of the KDP instance being tested
16+
float_fractional_tolerance:
17+
Fraction of the reference value of floating-point numbers that the test db is allowed to deviate by
18+
"""
19+
with open(reference_json_path) as f:
20+
reference_db = json.load(f)
21+
with MontyClient(test_db_path, cache_modified=0) as client:
22+
db = client.db
23+
for i, reference_result in enumerate(reference_db):
24+
print ("Processing reference result %d of %d"%(i,len(reference_db)),end="\r")
25+
reference_uuid = reference_result["meta"]["uuid"]
26+
reference_runner_and_subject = "-".join(reference_uuid.split("-")[:-2])
27+
reference_instance_id = int(reference_result["instance-id"]["$numberInt"])
28+
for key in reference_result:
29+
if key == "vc-comment":
30+
# VC comments may be a string with float numbers embedded, too much hassle to test
31+
continue
32+
if isinstance(reference_result[key],dict):
33+
if "source-value" in reference_result[key]:
34+
# ok, this is a property key, search for this result
35+
# generic error message
36+
error_message_specifying_pair_and_key = "\n\nTest failed while comparing to key '%s' in instance-id %d in reference runner-subject pair %s:\n" \
37+
%(key,reference_instance_id,reference_runner_and_subject)
38+
39+
# get numpy array of the source-value from the reference db
40+
reference_source_value_array = np.asarray(reference_result[key]["source-value"])
41+
42+
43+
44+
"""
45+
MONTYDB VERSION NOTE:
46+
In 2.1.1, the version in the KDP, querying the /pipeline/db like this gives and requires dicts
47+
e.g. {"$numberDouble": "0.70535806"} for typed values, just like the raw json in the reference db.
48+
However, if we ever upgrade to 2.5.2 (or even some earlier versions might have this),
49+
typed values just have the value.
50+
"""
51+
52+
# query the test DB
53+
query={
54+
"meta.uuid":{"$regex":reference_runner_and_subject},
55+
"instance-id.$numberInt":str(reference_instance_id)
56+
}
57+
project={key:1,"_id":False}
58+
cursor=db.data.find(query,projection=project)
59+
60+
# get numpy array of the source-value from the DB we are testing
61+
try:
62+
test_source_value_array = np.asarray(next(cursor)[key]["source-value"])
63+
except StopIteration:
64+
assert False, error_message_specifying_pair_and_key+"No matches found in test DB."
65+
except:
66+
raise RuntimeError("Unexpected exception when searching test DB")
67+
68+
# should be only one result, test this
69+
try:
70+
next(cursor)
71+
assert False, error_message_specifying_pair_and_key+"Multiple matches found in test DB."
72+
except StopIteration:
73+
pass
74+
except:
75+
raise RuntimeError("Unexpected exception when searching test DB")
76+
77+
# error message segment for displaying the source-values
78+
error_message_showing_source_values = "\nMismatch found between reference value\n\n%s\n\nand test value\n\n%s\n\n" % \
79+
(reference_source_value_array,test_source_value_array)
80+
81+
# arrays should be the same shape
82+
assert reference_source_value_array.shape == test_source_value_array.shape, \
83+
error_message_specifying_pair_and_key + error_message_showing_source_values + "Arrays are different shapes."
84+
if reference_source_value_array.dtype != "object":
85+
# this means it's strings, if its doubles or ints, each entry is a dict e.g. "$numberDouble": "0.70535806"
86+
assert (reference_source_value_array == test_source_value_array).all(), \
87+
error_message_specifying_pair_and_key + error_message_showing_source_values + "Non-numerical values are not equal."
88+
else: # the reference ndarray is dicts, so we have to look at data types
89+
reference_source_value_array_flat=reference_source_value_array.flat
90+
if len(reference_source_value_array_flat[0].keys()) != 1:
91+
raise RuntimeError("\n\nElements of reference DB value\n\n%s\n\nare not single-key dicts as expected."%reference_source_value_array)
92+
mongo_dtype = list(reference_source_value_array_flat[0].keys())[0]
93+
for reference_source_value_dict,test_source_value_dict in zip(reference_source_value_array_flat,test_source_value_array.flat):
94+
if mongo_dtype == "$numberDouble":
95+
reference_source_value = float(reference_source_value_dict[mongo_dtype])
96+
test_source_value = float(test_source_value_dict[mongo_dtype])
97+
assert abs(reference_source_value-test_source_value) <= abs(float_fractional_tolerance*reference_source_value), \
98+
error_message_specifying_pair_and_key + error_message_showing_source_values + \
99+
"Floating point values are not within the requested fractional tolerance %f"%float_fractional_tolerance
100+
elif mongo_dtype == "$numberInt":
101+
reference_source_value = int(reference_source_value_dict[mongo_dtype])
102+
test_source_value = int(test_source_value_dict[mongo_dtype])
103+
assert reference_source_value == test_source_value, \
104+
error_message_specifying_pair_and_key + error_message_showing_source_values + \
105+
"Integer values are not equal."
106+
else:
107+
raise RuntimeError("Unexpected data type %s in reference DB"%mongo_dtype)
108+
109+
if __name__=='__main__':
110+
reference_json_file = "data.json"
111+
test_db = "/pipeline/db"
112+
compare_db_to_reference(reference_json_file,test_db)
113+
print("SUCCESS! All results provided in reference database were successfully matched.")

docker/test/test_scripts_and_data/data.json

Lines changed: 30 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
3+
kimitems install -D EquilibriumCrystalStructure_AB_hP10_156_2a2bc_2a2bc_CSi__TE_758846131690_001
4+
kimitems install -D EquilibriumCrystalStructure_AB_hR6_160_3a_3a_SZn__TE_368210937505_001
5+
kimitems install -D EquilibriumCrystalStructure_A_cI82_217_acgh_Si__TE_858705144968_001
6+
kimitems install -D EquilibriumCrystalStructure_A_oP24_58_eg2h_S__TE_654572373022_001
7+
kimitems install -D EquilibriumCrystalStructure_A_oC16_65_pq_C__TE_970978470247_001
8+
kimitems install -D EquilibriumCrystalStructure_A_tI8_139_h_C__TE_939583133718_001
9+
kimitems install -D EquilibriumCrystalStructure_A2B_cP12_205_c_a_SZn__TE_887144277034_001
10+
kimitems install -D EquilibriumCrystalStructure_A2B_tP6_131_i_e_CSi__TE_797499413755_001
11+
kimitems install -D EquilibriumCrystalStructure_A_oF16_69_gh_Si__TE_099421378389_001
12+
kimitems install -D EquilibriumCrystalStructure_A_mP32_13_8g_S__TE_685644464884_001
13+
kimitems install -D EquilibriumCrystalStructure_AB_cF8_216_a_c_SZn__TE_981216532817_001
14+
kimitems install -D EquilibriumCrystalStructure_A_mC16_12_4i_Si__TE_709261317000_001
15+
kimitems install -D EquilibriumCrystalStructure_A_aP28_2_14i_S__TE_073817817914_001
16+
kimitems install -D EquilibriumCrystalStructure_A_oI120_71_lmn6o_C__TE_407657597689_001
17+
kimitems install -D SW_ZhouWardMartin_2013_CdTeZnSeHgS__MO_503261197030_003
18+
kimitems install -D Sim_LAMMPS_TersoffZBL_DevanathanDiazdelaRubiaWeber_1998_SiC__SM_578912636995_000
19+
20+
pipeline-database set local
21+
22+
pipeline-run-matches \*_TE_\*

0 commit comments

Comments
 (0)