Skip to content

Commit

Permalink
Merge pull request #14 from usnistgov/develop
Browse files Browse the repository at this point in the history
Train from folder, and other minor updates.
  • Loading branch information
knc6 authored May 18, 2021
2 parents 69c77a2 + a9c1160 commit 43d8027
Show file tree
Hide file tree
Showing 85 changed files with 1,769 additions and 55 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
# ALIGNN
Atomistic Line Graph Neural Network

>>> python alignn/scripts/train_folder.py --root_dir "alignn/examples/sample_data" --config "alignn/examples/sample_data/config_example_regrssion.json"
2 changes: 1 addition & 1 deletion alignn/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
"""Version number."""
__version__ = "2021.5.11"
__version__ = "2021.5.16"
14 changes: 10 additions & 4 deletions alignn/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"dfpt_piezo_max_dij",
"gap pbe",
"e_form",
"e_hull",
"mu_b",
"bulk modulus",
"shear modulus",
Expand All @@ -81,6 +82,7 @@
"A",
"B",
"C",
"target",
]


Expand All @@ -90,7 +92,9 @@ class TrainingConfig(BaseSettings):
version: str = VERSION

# dataset configuration
dataset: Literal["dft_3d", "dft_2d", "megnet", "qm9"] = "dft_3d"
dataset: Literal[
"dft_3d", "dft_2d", "megnet", "qm9", "user_data"
] = "dft_3d"
target: TARGET_ENUM = "formation_energy_peratom"
atom_features: Literal["basic", "atomic_number", "cfid", "cgcnn"] = "cgcnn"
neighbor_strategy: Literal["k-nearest", "voronoi"] = "k-nearest"
Expand All @@ -108,7 +112,8 @@ class TrainingConfig(BaseSettings):
train_ratio: Optional[float] = 0.8
val_ratio: Optional[float] = 0.1
test_ratio: Optional[float] = 0.1
epochs: int = 200
target_multiplication_factor: Optional[float] = None
epochs: int = 300
batch_size: int = 64
weight_decay: float = 0
learning_rate: float = 1e-2
Expand All @@ -119,7 +124,7 @@ class TrainingConfig(BaseSettings):
scheduler: Literal["onecycle", "none"] = "onecycle"
pin_memory: bool = False
save_dataloader: bool = False
write_checkpoint: bool = False
write_checkpoint: bool = True
write_predictions: bool = True
store_outputs: bool = True
progress: bool = True
Expand All @@ -138,7 +143,8 @@ class TrainingConfig(BaseSettings):
ALIGNNConfig,
DenseALIGNNConfig,
ACGCNNConfig,
] = CGCNNConfig(name="cgcnn")
] = ALIGNNConfig(name="alignn")
# ] = CGCNNConfig(name="cgcnn")

@root_validator()
def set_input_size(cls, values):
Expand Down
28 changes: 22 additions & 6 deletions alignn/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,14 @@ def get_torch_dataset(
df = pd.DataFrame(dataset)
vals = df[target].values
print("data range", np.max(vals), np.min(vals))

f = open("data_range", "w")
line = "Max=" + str(np.max(vals)) + "\n"
f.write(line)
line = "Min=" + str(np.min(vals)) + "\n"
f.write(line)
f.close()

graphs = load_graphs(
df,
name=name,
Expand All @@ -197,28 +205,30 @@ def get_torch_dataset(

def get_train_val_loaders(
dataset: str = "dft_3d",
dataset_array=[],
target: str = "formation_energy_peratom",
atom_features: str = "atomic_number",
atom_features: str = "cgcnn",
neighbor_strategy: str = "k-nearest",
n_train=None,
n_val=None,
n_test=None,
train_ratio=None,
val_ratio=0.1,
test_ratio=0.1,
batch_size: int = 8,
batch_size: int = 5,
standardize: bool = False,
line_graph: bool = False,
line_graph: bool = True,
split_seed: int = 123,
workers: int = 0,
pin_memory: bool = True,
save_dataloader: bool = True,
save_dataloader: bool = False,
filename: str = "sample",
id_tag: str = "jid",
use_canonize: bool = False,
cutoff: float = 8.0,
max_neighbors: int = 12,
classification_threshold: Optional[float] = None,
target_multiplication_factor: Optional[float] = None,
):
"""Help function to set up Jarvis train and val dataloaders."""
train_sample = filename + "_train.data"
Expand Down Expand Up @@ -254,7 +264,11 @@ def get_train_val_loaders(
# print("test", len(test_loader.dataset))
else:

d = jdata(dataset)
if not dataset_array:
d = jdata(dataset)
else:
d = dataset_array

dat = []
if classification_threshold is not None:
print(
Expand All @@ -267,6 +281,8 @@ def get_train_val_loaders(
print("Converting target data into 1 and 0.")
for i in d:
if i[target] != "na" and not math.isnan(i[target]):
if target_multiplication_factor is not None:
i[target] = i[target] * target_multiplication_factor
if classification_threshold is not None:
if i[target] <= classification_threshold:
i[target] = 0
Expand Down Expand Up @@ -297,7 +313,7 @@ def get_train_val_loaders(
ids_train_val_test["id_train"] = [dat[i][id_tag] for i in id_train]
ids_train_val_test["id_val"] = [dat[i][id_tag] for i in id_val]
ids_train_val_test["id_test"] = [dat[i][id_tag] for i in id_test]
dumpjson(data=ids_train_val_test, filename="ids_train_val_tes.json")
dumpjson(data=ids_train_val_test, filename="ids_train_val_test.json")
dataset_train = [dat[x] for x in id_train]
dataset_val = [dat[x] for x in id_val]
dataset_test = [dat[x] for x in id_test]
Expand Down
11 changes: 11 additions & 0 deletions alignn/examples/sample_data/POSCAR-JVASP-10.vasp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
System
1.0
1.6777483798834445 -2.9059452409270157 -1.1e-15
1.6777483798834438 2.9059452409270126 -7e-16
-6.5e-15 -8e-16 6.220805465667012
V Se
1 2
direct
0.0 0.0 0.0
0.6666669999999968 0.3333330000000032 0.7479606991085345
0.3333330000000032 0.6666669999999968 0.252039300891465
12 changes: 12 additions & 0 deletions alignn/examples/sample_data/POSCAR-JVASP-107772.vasp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
System
1.0
4.376835486482439 0.0086562096165887 7.148251977291244
2.0211490103296166 3.8822313794698684 7.148251977291244
0.0142338540946976 0.008656214510917 8.38176620441039
Bi Sb
3 1
direct
0.11687114695010013 0.11687114695010009 0.11687114695134818
0.885057350916569 0.8850573509165686 0.8850573509144881
0.3806761740317465 0.3806761740317465 0.3806761740305207
0.6173953281015849 0.6173953281015848 0.6173953281036431
24 changes: 24 additions & 0 deletions alignn/examples/sample_data/POSCAR-JVASP-13526.vasp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
System
1.0
7.091458561131444 0.0 0.0
0.0 12.284128695721973 0.0
-8.862874621478095 0.0 25.0
Y Br
4 12
direct
0.033346999999999086 0.6240773822144681 0.1871170000000006
0.033346999999999086 0.9574286177855293 0.1871170000000006
0.5333479999999966 0.12407738221446811 0.1871170000000006
0.5333479999999966 0.4574286177855292 0.1871170000000006
0.2891270840017781 0.46667191911829303 0.2510176333839372
0.2891270840017781 0.11483508088170911 0.2510176333839372
0.2613405348547832 0.7907530000000023 0.2510114569972214
0.7891270840017786 0.9666709191182953 0.2510176333839372
0.7891270840017786 0.6148350808817092 0.2510176333839372
0.7613405348547837 0.2907530000000023 0.2510114569972214
0.30535446514521963 0.2907530000000023 0.1232235430027774
0.2775679159982247 0.9666709191182953 0.123216366616057
0.2775679159982247 0.6148350808817092 0.123216366616057
0.8053554651452168 0.7907530000000023 0.1232235430027774
0.7775679159982244 0.46667191911829303 0.123216366616057
0.7775679159982244 0.11483508088170911 0.123216366616057
10 changes: 10 additions & 0 deletions alignn/examples/sample_data/POSCAR-JVASP-1372.vasp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
System
1.0
3.5058938597621094 -3.081249e-10 2.0241289627124215
1.1686312862968669 3.3053879820023613 2.0241289627124215
-8.715088e-10 -6.162497e-10 4.048256928443838
Al As
1 1
direct
0.0 0.0 0.0
0.24999999999999997 0.25 0.24999999999999997
20 changes: 20 additions & 0 deletions alignn/examples/sample_data/POSCAR-JVASP-14014.vasp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
System
1.0
4.157436115454804 -0.0 0.0
-0.0 7.038494037846648 0.0
0.0 0.0 7.411178065479046
Tb Mn Si
4 4 4
direct
0.25 0.5014870121743014 0.1863876024079978
0.75 0.49851298782569875 0.8136123975920022
0.25 0.0014870121743013 0.3136123975920026
0.75 0.9985129878256985 0.6863876024079979
0.75 0.8608859093979077 0.06027225572734521
0.25 0.1391140906020922 0.939727744272655
0.75 0.3608859093979077 0.43972774427265476
0.25 0.6391140906020923 0.5602722557273451
0.25 0.792634730215007 0.8919146343653592
0.75 0.207365269784993 0.10808536563464112
0.25 0.2926347302150071 0.6080853656346409
0.75 0.707365269784993 0.3919146343653588
11 changes: 11 additions & 0 deletions alignn/examples/sample_data/POSCAR-JVASP-14441.vasp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
System
1.0
2.8173501021142346 -0.0 0.0
-1.4086750510571173 2.439896157530945 0.0
0.0 0.0 24.551775
Co O
1 2
direct
0.2690539999999971 0.9290120000000003 0.0926970000000011
0.6023870000000002 0.595678999999997 0.1307621356947131
0.9357210000000009 0.26234500000000344 0.0546328643052866
15 changes: 15 additions & 0 deletions alignn/examples/sample_data/POSCAR-JVASP-14873.vasp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
System
1.0
4.191262576674699 0.0 -0.0
-0.0 4.191262576674699 0.0
-0.0 0.0 4.191262576674699
Sr B
1 6
direct
0.0 0.0 0.0
0.2028453684309125 0.5 0.5
0.5 0.5 0.7971546315690875
0.5 0.5 0.2028453684309125
0.5 0.2028453684309125 0.5
0.5 0.7971546315690875 0.5
0.7971546315690875 0.5 0.5
12 changes: 12 additions & 0 deletions alignn/examples/sample_data/POSCAR-JVASP-15345.vasp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
System
1.0
3.5666343258756448 0.0 0.0
0.0 3.60492483256326 -1.0516480500920402
0.0 0.0043800721536433 3.7551864245512623
Y Co C
1 1 2
direct
0.0 0.9970518040927455 0.00294819590736377
0.5 0.6150401254054609 0.3849598745944179
0.5 0.15192770422861318 0.5440196337270639
0.5 0.4559803662731792 0.8480722957711558
10 changes: 10 additions & 0 deletions alignn/examples/sample_data/POSCAR-JVASP-1996.vasp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
System
1.0
3.93712543178282 0.0 2.273100275741533
1.3123751439276066 3.7119571065192623 2.273100275741533
0.0 0.0 4.546200551483066
Na I
1 1
direct
0.0 0.0 0.0
0.5 0.5 0.5
9 changes: 9 additions & 0 deletions alignn/examples/sample_data/POSCAR-JVASP-21210.vasp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
System
1.0
1.6712283e-08 -2.508029669761222 3.5458136263853106
-2.172017276374766 1.254014874098203 3.545813646368687
-2.17201803290572 -1.254014795663004 -3.5458136064019246
Xe
1
direct
0.0 0.0 0.0
13 changes: 13 additions & 0 deletions alignn/examples/sample_data/POSCAR-JVASP-22556.vasp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
System
1.0
3.790914410660539 -0.0 0.0
0.0 3.790914410660539 0.0
-0.0 -0.0 3.790914410660539
Sr Fe O
1 1 3
direct
0.4999990000000025 0.4999990000000025 0.4999990000000025
0.0 0.0 0.0
0.4999990000000025 0.0 0.0
0.0 0.4999990000000025 0.0
0.0 0.0 0.4999990000000025
14 changes: 14 additions & 0 deletions alignn/examples/sample_data/POSCAR-JVASP-27901.vasp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
System
1.0
3.4878362323679837 3.6597344e-09 0.0
-1.7439186098402102 3.020554822453009 0.0
0.0 0.0 25.743165
Sc H Cl
2 2 2
direct
0.6666669999999968 0.3333330000000032 0.45082619084199527
0.33333300000000327 0.6666669999999969 0.5491738091580051
0.6666669999999968 0.3333330000000032 0.5287351839124973
0.33333300000000327 0.6666669999999969 0.47126481608750276
0.0 0.0 0.3881804432720387
0.0 0.0 0.6118195567279613
16 changes: 16 additions & 0 deletions alignn/examples/sample_data/POSCAR-JVASP-28397.vasp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
System
1.0
0.0 -3.9587610833154616 0.0
-6.655928089533787 0.0 0.0
0.0 0.0 -23.94045079597872
Si S
4 4
direct
0.0 0.0 0.5217263648738928
0.0 0.5 0.5217263648738928
0.5 0.0 0.4661843287970869
0.5 0.5 0.4661843287970869
0.0524900550457348 0.7500000000000001 0.5792751627500841
0.9475099449542649 0.25 0.5792751627500841
0.4474867899417421 0.7500000000000001 0.40863414357892813
0.5525132100582582 0.25 0.40863414357892813
17 changes: 17 additions & 0 deletions alignn/examples/sample_data/POSCAR-JVASP-28565.vasp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
System
1.0
3.3542337275744103 0.0 0.0
-1.6771168637872051 2.904850045503021 0.0002624763854255
0.0 0.0027191662067697 29.227006366170723
Te Mo W Se S
2 2 1 2 2
direct
0.3332869375319439 0.6665748750638851 0.40880470960271253
0.3334050587801155 0.6668121175602401 0.2788667649202174
0.3335186248083656 0.6670362496167267 0.11458088390572692
0.6666801663591748 0.33335933271835083 0.3438741864905265
0.3331138284834239 0.6662286569668452 0.5825261819744669
0.6664959135073409 0.3329918270146898 0.5252624785410095
0.6664002633646019 0.3327995267292049 0.639695963563112
0.6669034856871763 0.33380597137434753 0.06276093238425431
0.6667957214778616 0.3335914429557147 0.1664678986179713
20 changes: 20 additions & 0 deletions alignn/examples/sample_data/POSCAR-JVASP-28634.vasp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
System
1.0
3.2250494729190726 2.216578e-10 2.163e-13
-1.6125242360333125 2.7929740932668943 -8.4754501616e-06
6.6135e-12 -9.7386036979e-05 34.14068378844537
Mo W Se S
1 3 2 6
direct
0.33331504683701274 0.6666300936741254 0.0934536896030271
0.33331656497272827 0.6666341299456554 0.47208556491119213
0.6666698924990063 0.33333978499784117 0.28247993950367123
0.6666991220003533 0.3333972440007849 0.6548932577640771
0.33334341592455036 0.6666888318491291 0.3328984548376194
0.33332779768550075 0.6666565953711356 0.2320623862553914
0.33337390316228616 0.6667488063245635 0.7006769649140224
0.6666482437297062 0.33329648745935525 0.0479187308537724
0.6666490346540366 0.33329706930798436 0.4262562969343839
0.6666480620607286 0.33329512412140816 0.1390473399063092
0.6666512247313715 0.33330144946262313 0.5179005541158488
0.33335669174272836 0.6667143834853922 0.6090748204006833
20 changes: 20 additions & 0 deletions alignn/examples/sample_data/POSCAR-JVASP-28704.vasp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
System
1.0
3.292134155794691 0.0 0.0
-1.6460670778973454 2.8510786681143565 -3.615752048e-06
0.0 -0.0001768206441563 34.978246270650075
Mo W Se S
3 1 6 2
direct
0.3333192249247229 0.6666384498494459 0.0966675137812058
0.6666558392026922 0.3333126784053811 0.2791091321598709
0.6666926464398288 0.3333852928796507 0.6584266681105794
0.3333321581155246 0.666664316231042 0.468712621722382
0.3333230348691514 0.6666470697383001 0.3273013286877133
0.3333590853838843 0.6667201707677635 0.7065686651425439
0.6666558450522622 0.3333116901045159 0.4202334807678751
0.6666765519168195 0.3333521038336415 0.5171906710959798
0.3333210915930135 0.6666421831860199 0.23092332016136433
0.3333560781404684 0.6667131562809414 0.6102231914914819
0.6666426939013361 0.33328538780266426 0.0528105185440566
0.6666647504603075 0.33332850092061717 0.1405808883349591
Loading

0 comments on commit 43d8027

Please sign in to comment.