-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
34 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,8 +11,8 @@ | |
__email__ = "[email protected]" | ||
|
||
module_dir = os.path.join(os.path.dirname(os.path.abspath(__file__))) | ||
test_tasks = os.path.join(module_dir, "..","..","..", "..", "test_files", | ||
"vasp", "elastic_tasks.json") | ||
test_tasks = os.path.join(module_dir, "..", "..", "..", "..", "test_files", "vasp", "elastic_tasks.json") | ||
|
||
|
||
class ElasticBuilderTest(unittest.TestCase): | ||
@classmethod | ||
|
@@ -27,24 +27,26 @@ def setUpClass(cls): | |
# Generate test materials collection | ||
cls.test_materials = MongoStore("test_emmet", "materials") | ||
cls.test_materials.connect() | ||
opt_docs = cls.test_tasks.query(["output.structure", "formula_pretty"], | ||
{"task_label": "structure optimization"}) | ||
mat_docs = [{"material_id": "mp-{}".format(n), | ||
"structure": opt_doc['output']['structure'], | ||
"pretty_formula": opt_doc['formula_pretty']} | ||
for n, opt_doc in enumerate(opt_docs)] | ||
opt_docs = cls.test_tasks.query(["output.structure", "formula_pretty"], { | ||
"task_label": "structure optimization" | ||
}) | ||
mat_docs = [{ | ||
"material_id": "mp-{}".format(n), | ||
"structure": opt_doc['output']['structure'], | ||
"pretty_formula": opt_doc['formula_pretty'] | ||
} for n, opt_doc in enumerate(opt_docs)] | ||
cls.test_materials.update(mat_docs, key='material_id', update_lu=False) | ||
|
||
def test_builder(self): | ||
ec_builder = ElasticBuilder(self.test_tasks, self.test_elasticity, | ||
self.test_materials, incremental=False) | ||
ec_builder = ElasticBuilder(self.test_tasks, self.test_elasticity, self.test_materials, incremental=False) | ||
ec_builder.connect() | ||
for t in ec_builder.get_items(): | ||
processed = ec_builder.process_item(t) | ||
if processed: | ||
pass | ||
else: | ||
import nose; nose.tools.set_trace() | ||
import nose | ||
nose.tools.set_trace() | ||
runner = Runner([ec_builder]) | ||
runner.run() | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,8 +9,7 @@ | |
__email__ = "[email protected]" | ||
|
||
module_dir = os.path.join(os.path.dirname(os.path.abspath(__file__))) | ||
test_tasks = os.path.join(module_dir, "..", "..", "..", "..", | ||
"test_files", "mpworks_tasks.json") | ||
test_tasks = os.path.join(module_dir, "..", "..", "..", "..", "test_files", "mpworks_tasks.json") | ||
|
||
|
||
class MPWorksCompatibilityBuilderTest(unittest.TestCase): | ||
|
@@ -22,9 +21,7 @@ def setUp(self): | |
self.elasticity.connect() | ||
|
||
def test_builder(self): | ||
mpw_builder = MPWorksCompatibilityBuilder(self.test_tasks, | ||
self.elasticity, | ||
incremental=False) | ||
mpw_builder = MPWorksCompatibilityBuilder(self.test_tasks, self.elasticity, incremental=False) | ||
items = mpw_builder.get_items() | ||
processed = [mpw_builder.process_item(item) for item in items] | ||
mpw_builder.update_targets(processed) | ||
|
@@ -37,12 +34,10 @@ def test_set_mongolike(self): | |
self.assertEqual(test_dict["new"]["value"], 5) | ||
|
||
def test_convert_mpworks_to_atomate(self): | ||
doc = self.test_tasks.collection.find_one( | ||
{"task_type": {"$regex": "deformed"}}) | ||
doc = self.test_tasks.collection.find_one({"task_type": {"$regex": "deformed"}}) | ||
new_doc = convert_mpworks_to_atomate(doc) | ||
self.assertTrue('hubbards' in new_doc['input']) | ||
doc = self.test_tasks.collection.find_one( | ||
{"task_type": {"$regex": "(2x)"}}) | ||
doc = self.test_tasks.collection.find_one({"task_type": {"$regex": "(2x)"}}) | ||
new_doc = convert_mpworks_to_atomate(doc) | ||
self.assertTrue('hubbards' in new_doc['input']) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,67 +2,51 @@ | |
import os | ||
|
||
from emmet.vasp.builders.structure_similarity import * | ||
from maggma.stores import MongoStore | ||
from maggma.stores import MemoryStore, JSONStore | ||
|
||
from monty.serialization import loadfn | ||
|
||
__author__ = "Nils E. R. Zimmermann" | ||
__email__ = "[email protected]" | ||
|
||
module_dir = os.path.join(os.path.dirname(os.path.abspath(__file__))) | ||
test_site_fp_stats = os.path.join(module_dir, "..","..","..", "..", "test_files", | ||
"site_fingerprint_stats.json") | ||
test_site_fp_stats = os.path.join(module_dir, "..", "..", "..", "..", "test_files", "site_fingerprint_stats.json") | ||
|
||
|
||
class StructureSimilarityBuilderTest(unittest.TestCase): | ||
def setUp(self): | ||
# Set up test db, etc. | ||
self.test_site_descriptors = MongoStore("test_emmet", | ||
"struct_sim_site_fp", | ||
key="task_id") | ||
self.test_site_descriptors = JSONStore(test_site_fp_stats) | ||
self.test_site_descriptors.connect() | ||
self.site_fp_docs = loadfn(test_site_fp_stats, cls=None) | ||
self.test_site_descriptors.update(self.site_fp_docs) | ||
self.test_structure_similarity = MongoStore("test_emmet", | ||
"struct_sim_struct_sim", | ||
"task_ids") | ||
self.test_structure_similarity = MemoryStore("struct_sim_struct_sim") | ||
|
||
def test_builder(self): | ||
sim_builder = StructureSimilarityBuilder( | ||
self.test_site_descriptors, | ||
self.test_structure_similarity) | ||
sim_builder = StructureSimilarityBuilder(self.test_site_descriptors, self.test_structure_similarity) | ||
sim_builder.connect() | ||
for t in sim_builder.get_items(): | ||
processed = sim_builder.process_item(t) | ||
if processed: | ||
pass | ||
else: | ||
import nose; nose.tools.set_trace() | ||
import nose | ||
nose.tools.set_trace() | ||
|
||
def test_get_all_site_descriptors(self): | ||
sim_builder = StructureSimilarityBuilder( | ||
self.test_site_descriptors, | ||
self.test_structure_similarity) | ||
sim_builder = StructureSimilarityBuilder(self.test_site_descriptors, self.test_structure_similarity) | ||
for i in range(3): | ||
d = sim_builder.get_similarities( | ||
self.site_fp_docs[i], | ||
self.site_fp_docs[i]) | ||
d = sim_builder.get_similarities(self.site_fp_docs[i], self.site_fp_docs[i]) | ||
self.assertAlmostEqual(d['cos'], 1) | ||
self.assertAlmostEqual(d['dist'], 0) | ||
d = sim_builder.get_similarities( | ||
self.site_fp_docs[0], | ||
self.site_fp_docs[1]) | ||
d = sim_builder.get_similarities(self.site_fp_docs[0], self.site_fp_docs[1]) | ||
self.assertAlmostEqual(d['cos'], 0.0013649) | ||
self.assertAlmostEqual(d['dist'], 2.6866749) | ||
d = sim_builder.get_similarities( | ||
self.site_fp_docs[0], | ||
self.site_fp_docs[2]) | ||
d = sim_builder.get_similarities(self.site_fp_docs[0], self.site_fp_docs[2]) | ||
self.assertAlmostEqual(d['cos'], 0.0013069) | ||
self.assertAlmostEqual(d['dist'], 2.6293889) | ||
d = sim_builder.get_similarities( | ||
self.site_fp_docs[1], | ||
self.site_fp_docs[2]) | ||
d = sim_builder.get_similarities(self.site_fp_docs[1], self.site_fp_docs[2]) | ||
self.assertAlmostEqual(d['cos'], 0.0012729) | ||
self.assertAlmostEqual(d['dist'], 2.7235044) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |