diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index a2e557bb..ea33b34b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -38,4 +38,8 @@ jobs: coverage report -m codecov codecov --token="85bd9c5d-9e55-4f6d-bd69-350ee5e3bb41" - # alignn_train_folder.py --root_dir "alignn/examples/sample_data" --config "alignn/examples/sample_data/config_example.json" --output_dir=temp + echo 'Train folder' + train_folder.py -h + echo 'Pre-trained models' + pretrained.py -h + #train_folder.py --root_dir "alignn/examples/sample_data" --config "alignn/examples/sample_data/config_example.json" --output_dir=temp diff --git a/alignn/__init__.py b/alignn/__init__.py index e3deeb25..591e3080 100644 --- a/alignn/__init__.py +++ b/alignn/__init__.py @@ -1,2 +1,2 @@ """Version number.""" -__version__ = "2021.11.13" +__version__ = "2021.11.14" diff --git a/alignn/config.py b/alignn/config.py index 9420c82f..4cdd4adf 100644 --- a/alignn/config.py +++ b/alignn/config.py @@ -19,9 +19,13 @@ # from typing import List -VERSION = ( - subprocess.check_output(["git", "rev-parse", "HEAD"]).decode().strip() -) +try: + VERSION = ( + subprocess.check_output(["git", "rev-parse", "HEAD"]).decode().strip() + ) +except Exception as exp: + VERSION = "NA" + pass FEATURESET_SIZE = {"basic": 11, "atomic_number": 1, "cfid": 438, "cgcnn": 92} diff --git a/alignn/pretrained.py b/alignn/pretrained.py index a8f29971..0dc70e75 100644 --- a/alignn/pretrained.py +++ b/alignn/pretrained.py @@ -1,3 +1,5 @@ +#!/usr/bin/env python + """Module to download and load pre-trained ALIGNN models.""" import requests import os @@ -12,11 +14,119 @@ from jarvis.core.atoms import Atoms from jarvis.core.graphs import Graph -all_models = loadjson( - str(os.path.join(os.path.dirname(__file__), "pretrained_models.json")) -) - - +# Name of the model, figshare link, number of outouts +all_models = { + "jv_formation_energy_peratom_alignn": [ + "https://figshare.com/ndownloader/files/31458679", + 1, + ], + "jv_optb88vdw_total_energy_alignn": [ + "https://figshare.com/ndownloader/files/31459642", + 1, + ], + "jv_optb88vdw_bandgap_alignn": [ + "https://figshare.com/ndownloader/files/31459636", + 1, + ], + "jv_mbj_bandgap_alignn": [ + "https://figshare.com/ndownloader/files/31458694", + 1, + ], + "jv_spillage_alignn": [ + "https://figshare.com/ndownloader/files/31458736", + 1, + ], + "jv_slme_alignn": ["https://figshare.com/ndownloader/files/31458727", 1], + "jv_bulk_modulus_kv_alignn": [ + "https://figshare.com/ndownloader/files/31458649", + 1, + ], + "jv_shear_modulus_gv_alignn": [ + "https://figshare.com/ndownloader/files/31458724", + 1, + ], + "jv_n-Seebeck_alignn": [ + "https://figshare.com/ndownloader/files/31458718", + 1, + ], + "jv_n-powerfact_alignn": [ + "https://figshare.com/ndownloader/files/31458712", + 1, + ], + "jv_magmom_oszicar_alignn": [ + "https://figshare.com/ndownloader/files/31458685", + 1, + ], + "jv_kpoint_length_unit_alignn": [ + "https://figshare.com/ndownloader/files/31458682", + 1, + ], + "jv_avg_elec_mass_alignn": [ + "https://figshare.com/ndownloader/files/31458643", + 1, + ], + "jv_avg_hole_mass_alignn": [ + "https://figshare.com/ndownloader/files/31458646", + 1, + ], + "jv_epsx_alignn": ["https://figshare.com/ndownloader/files/31458667", 1], + "jv_mepsx_alignn": ["https://figshare.com/ndownloader/files/31458703", 1], + "jv_max_efg_alignn": [ + "https://figshare.com/ndownloader/files/31458691", + 1, + ], + "jv_ehull_alignn": ["https://figshare.com/ndownloader/files/31458658", 1], + "jv_dfpt_piezo_max_dielectric_alignn": [ + "https://figshare.com/ndownloader/files/31458652", + 1, + ], + "jv_dfpt_piezo_max_dij_alignn": [ + "https://figshare.com/ndownloader/files/31458655", + 1, + ], + "jv_exfoliation_energy_alignn": [ + "https://figshare.com/ndownloader/files/31458676", + 1, + ], + "mp_e_form_alignnn": [ + "https://figshare.com/ndownloader/files/31458811", + 1, + ], + "mp_gappbe_alignnn": [ + "https://figshare.com/ndownloader/files/31458814", + 1, + ], + "qm9_U0_alignn": ["https://figshare.com/ndownloader/files/31459054", 1], + "qm9_U_alignn": ["https://figshare.com/ndownloader/files/31459051", 1], + "qm9_alpha_alignn": ["https://figshare.com/ndownloader/files/31459027", 1], + "qm9_gap_alignn": ["https://figshare.com/ndownloader/files/31459036", 1], + "qm9_G_alignn": ["https://figshare.com/ndownloader/files/31459033", 1], + "qm9_HOMO_alignn": ["https://figshare.com/ndownloader/files/31459042", 1], + "qm9_LUMO_alignn": ["https://figshare.com/ndownloader/files/31459045", 1], + "qm9_ZPVE_alignn": ["https://figshare.com/ndownloader/files/31459057", 1], + "hmof_co2_absp_alignnn": [ + "https://figshare.com/ndownloader/files/31459198", + 5, + ], + "hmof_max_co2_adsp_alignnn": [ + "https://figshare.com/ndownloader/files/31459207", + 1, + ], + "hmof_surface_area_m2g_alignnn": [ + "https://figshare.com/ndownloader/files/31459222", + 1, + ], + "hmof_surface_area_m2cm3_alignnn": [ + "https://figshare.com/ndownloader/files/31459219", + 1, + ], + "hmof_pld_alignnn": ["https://figshare.com/ndownloader/files/31459216", 1], + "hmof_lcd_alignnn": ["https://figshare.com/ndownloader/files/31459201", 1], + "hmof_void_fraction_alignnn": [ + "https://figshare.com/ndownloader/files/31459228", + 1, + ], +} parser = argparse.ArgumentParser( description="Atomistic Line Graph Neural Network Pretrained Models" ) diff --git a/alignn/pretrained_models.json b/alignn/pretrained_models.json deleted file mode 100644 index 52821992..00000000 --- a/alignn/pretrained_models.json +++ /dev/null @@ -1,41 +0,0 @@ -{ - "jv_formation_energy_peratom_alignn":["https://figshare.com/ndownloader/files/31458679",1], - "jv_optb88vdw_total_energy_alignn":["https://figshare.com/ndownloader/files/31459642",1], - "jv_optb88vdw_bandgap_alignn":["https://figshare.com/ndownloader/files/31459636",1], - "jv_mbj_bandgap_alignn":["https://figshare.com/ndownloader/files/31458694",1], - "jv_spillage_alignn":["https://figshare.com/ndownloader/files/31458736",1], - "jv_slme_alignn":["https://figshare.com/ndownloader/files/31458727",1], - "jv_bulk_modulus_kv_alignn":["https://figshare.com/ndownloader/files/31458649",1], - "jv_shear_modulus_gv_alignn":["https://figshare.com/ndownloader/files/31458724",1], - "jv_n-Seebeck_alignn":["https://figshare.com/ndownloader/files/31458718",1], - "jv_n-powerfact_alignn":["https://figshare.com/ndownloader/files/31458712",1], - "jv_magmom_oszicar_alignn":["https://figshare.com/ndownloader/files/31458685",1], - "jv_kpoint_length_unit_alignn":["https://figshare.com/ndownloader/files/31458682",1], - "jv_avg_elec_mass_alignn":["https://figshare.com/ndownloader/files/31458643",1], - "jv_avg_hole_mass_alignn":["https://figshare.com/ndownloader/files/31458646",1], - "jv_epsx_alignn":["https://figshare.com/ndownloader/files/31458667",1], - "jv_mepsx_alignn":["https://figshare.com/ndownloader/files/31458703",1], - "jv_max_efg_alignn":["https://figshare.com/ndownloader/files/31458691",1], - "jv_ehull_alignn":["https://figshare.com/ndownloader/files/31458658",1], - "jv_dfpt_piezo_max_dielectric_alignn":["https://figshare.com/ndownloader/files/31458652",1], - "jv_dfpt_piezo_max_dij_alignn":["https://figshare.com/ndownloader/files/31458655",1], - "jv_exfoliation_energy_alignn":["https://figshare.com/ndownloader/files/31458676",1], - "mp_e_form_alignnn":["https://figshare.com/ndownloader/files/31458811",1], - "mp_gappbe_alignnn":["https://figshare.com/ndownloader/files/31458814",1], - "qm9_U0_alignn":["https://figshare.com/ndownloader/files/31459054",1], - "qm9_U_alignn":["https://figshare.com/ndownloader/files/31459051",1], - "qm9_alpha_alignn":["https://figshare.com/ndownloader/files/31459027",1], - "qm9_gap_alignn":["https://figshare.com/ndownloader/files/31459036",1], - "qm9_G_alignn":["https://figshare.com/ndownloader/files/31459033",1], - "qm9_HOMO_alignn":["https://figshare.com/ndownloader/files/31459042",1], - "qm9_LUMO_alignn":["https://figshare.com/ndownloader/files/31459045",1], - "qm9_ZPVE_alignn":["https://figshare.com/ndownloader/files/31459057",1], - "hmof_co2_absp_alignnn":["https://figshare.com/ndownloader/files/31459198",5], - "hmof_max_co2_adsp_alignnn":["https://figshare.com/ndownloader/files/31459207",1], - "hmof_surface_area_m2g_alignnn":["https://figshare.com/ndownloader/files/31459222",1], - "hmof_surface_area_m2cm3_alignnn":["https://figshare.com/ndownloader/files/31459219",1], - "hmof_pld_alignnn":["https://figshare.com/ndownloader/files/31459216",1], - "hmof_lcd_alignnn":["https://figshare.com/ndownloader/files/31459201",1], - "hmof_void_fraction_alignnn":["https://figshare.com/ndownloader/files/31459228",1] -} - diff --git a/alignn/tests/test_prop.py b/alignn/tests/test_prop.py index b69505bc..a6b47be3 100644 --- a/alignn/tests/test_prop.py +++ b/alignn/tests/test_prop.py @@ -36,14 +36,23 @@ def test_runtime_training(): - cmd1 = 'python alignn/scripts/train_folder.py --root_dir "alignn/examples/sample_data" --config "alignn/examples/sample_data/config_example.json"' + cmd1 = 'python alignn/train_folder.py --root_dir "alignn/examples/sample_data" --config "alignn/examples/sample_data/config_example.json"' os.system(cmd1) - cmd2 = 'python alignn/scripts/train_folder.py --root_dir "alignn/examples/sample_data" --classification_threshold 0.01 --config "alignn/examples/sample_data/config_example.json"' + cmd2 = 'python alignn/train_folder.py --root_dir "alignn/examples/sample_data" --classification_threshold 0.01 --config "alignn/examples/sample_data/config_example.json"' os.system(cmd2) - cmd3 = 'python alignn/scripts/train_folder.py --root_dir "alignn/examples/sample_data_multi_prop" --config "alignn/examples/sample_data/config_example.json"' + cmd3 = 'python alignn/train_folder.py --root_dir "alignn/examples/sample_data_multi_prop" --config "alignn/examples/sample_data/config_example.json"' os.system(cmd3) +def test_minor_configs(): + tmp = config + # tmp["log_tensorboard"] = True + tmp["n_early_stopping"] = 2 + tmp["model"]["name"] = "alignn" + config["write_predictions"] = True + result = train_dgl(tmp) + + def test_models(): """Test CGCNN end to end training.""" config["model"]["name"] = "dense_alignn" @@ -57,6 +66,7 @@ def test_models(): print() print() + config["write_predictions"] = True config["model"]["name"] = "alignn" t1 = time.time() result = train_dgl(config) @@ -172,7 +182,7 @@ def test_models(): config["model"]["name"] = "alignn_cgcnn" config["write_predictions"] = False - config["save_dataloader"] = False + config["save_dataloader"] = True config["classification_threshold"] = 0.0 t1 = time.time() result = train_dgl(config) @@ -226,6 +236,7 @@ def test_pretrained(): os.system(cmd1) +# test_minor_configs() # test_pretrained() # test_runtime_training() diff --git a/alignn/train.py b/alignn/train.py index 78d391fc..c473eaca 100644 --- a/alignn/train.py +++ b/alignn/train.py @@ -11,10 +11,15 @@ from typing import Any, Dict, Union import ignite import torch + from ignite.contrib.handlers import TensorboardLogger -from ignite.handlers.stores import EpochOutputStore +try: + from ignite.contrib.handlers.stores import EpochOutputStore + # For different version of pytorch-ignite +except Exception as exp: + from ignite.handlers.stores import EpochOutputStore -# from ignite.contrib.handlers.stores import EpochOutputStore + pass from ignite.handlers import EarlyStopping from ignite.contrib.handlers.tensorboard_logger import ( global_step_from_engine, diff --git a/alignn/scripts/train_folder.py b/alignn/train_folder.py similarity index 99% rename from alignn/scripts/train_folder.py rename to alignn/train_folder.py index 6b07cd3c..18b08c36 100644 --- a/alignn/scripts/train_folder.py +++ b/alignn/train_folder.py @@ -1,3 +1,5 @@ +#!/usr/bin/env python + """Module to train for a folder with formatted dataset.""" import csv import os diff --git a/setup.py b/setup.py index 52d948cf..39dbeb43 100644 --- a/setup.py +++ b/setup.py @@ -10,7 +10,7 @@ setuptools.setup( name="alignn", - version="2021.11.13", + version="2021.11.14", author="Kamal Choudhary, Brian DeCost", author_email="kamal.choudhary@nist.gov", description="alignn", @@ -33,12 +33,7 @@ "pyparsing>=2.2.1,<3", ], # scripts=["alignn/alignn_train_folder.py"], - entry_points={ - "console_scripts": [ - "train_folder=alignn.script.train_folder" - "pretrained=alignn.pretrained" - ], - }, + scripts=['alignn/pretrained.py','alignn/train_folder.py'], long_description=long_description, long_description_content_type="text/markdown", url="https://github.com/usnistgov/alignn",