-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from usnistgov/develop
Merge Develop
- Loading branch information
Showing
14 changed files
with
603 additions
and
28 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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
"""Version number.""" | ||
__version__ = "2021.5.16" | ||
__version__ = "2021.06.18" |
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
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
{ | ||
"id-oqmd_3d_no_cfid":[ | ||
"_oqmd_band_gap", | ||
"_oqmd_delta_e", | ||
"_oqmd_stability"], | ||
"id-mp_3d_2020":["energy_per_atom","formation_energy_per_atom","band_gap","e_above_hull"], | ||
"id-megnet2":["formation_energy_per_atom"], | ||
"jid-dft_2d":["formation_energy_peratom","optb88vdw_bandgap"], | ||
"jid-qe_tb":["indir_gap"], | ||
"jid-dft_3d":[ | ||
"formation_energy_peratom", | ||
"optb88vdw_bandgap", | ||
"optb88vdw_total_energy", | ||
"bulk_modulus_kv", | ||
"shear_modulus_gv", | ||
"mbj_bandgap", | ||
"slme", | ||
"magmom_oszicar", | ||
"epsx", | ||
"spillage", | ||
"kpoint_length_unit", | ||
"encut", | ||
"epsy", | ||
"epsz", | ||
"mepsx", | ||
"mepsy", | ||
"mepsz", | ||
"max_ir_mode", | ||
"min_ir_mode", | ||
"n-Seebeck", | ||
"p-Seebeck", | ||
"n-powerfact", | ||
"p-powerfact", | ||
"ehull", | ||
"exfoliation_energy", | ||
"dfpt_piezo_max_dielectric", | ||
"dfpt_piezo_max_eij", | ||
"dfpt_piezo_max_dij"], | ||
"id-polymer_genome":["gga_gap"], | ||
"cod_id-omdb":["bandgap"], | ||
"id-megnet":["e_form","gap pbe"], | ||
"jid-qe_tb":["f_enp","indir_gap"] | ||
|
||
} |
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 |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import torch | ||
from jarvis.core.atoms import Atoms | ||
from jarvis.core.graphs import Graph | ||
from alignn.models.alignn import ALIGNN | ||
|
||
# from jarvis.analysis.structure.spacegroup import Spacegroup3D | ||
from jarvis.db.figshare import get_jid_data | ||
from jarvis.analysis.defects.vacancy import Vacancy | ||
from jarvis.analysis.thermodynamics.energetics import unary_energy | ||
|
||
device = "cpu" | ||
if torch.cuda.is_available(): | ||
device = torch.device("cuda") | ||
|
||
|
||
def atom_to_energy(atoms=None, model=None): | ||
"""Get energy for Atoms.""" | ||
g, lg = Graph.atom_dgl_multigraph(atoms) | ||
out_data = ( | ||
model([g.to(device), lg.to(device)]) | ||
.detach() | ||
.cpu() | ||
.numpy() | ||
.flatten() | ||
.tolist()[0] | ||
) | ||
return out_data | ||
|
||
|
||
def get_defect_form_en( | ||
jid="JVASP-1002", | ||
model_path="JV15/jv_optb88vdw_total_energy_alignn/checkpoint_300.pt", | ||
dataset="dft_3d", | ||
): | ||
"""Predict defect formation energy ???.""" | ||
model = ALIGNN() | ||
model.load_state_dict(torch.load(model_path, map_location=device)["model"]) | ||
# model=torch.load('checkpoint_250.pt')['model'] | ||
model.to(device) | ||
model.eval() | ||
|
||
atoms = Atoms.from_dict(get_jid_data(jid=jid, dataset=dataset)["atoms"]) | ||
bulk_en_pa = atom_to_energy(atoms=atoms, model=model) # *atoms.num_atoms | ||
|
||
strts = Vacancy(atoms).generate_defects( | ||
on_conventional_cell=False, enforce_c_size=8, extend=1 | ||
) | ||
for j in strts: | ||
strt = Atoms.from_dict(j.to_dict()["defect_structure"]) | ||
name = ( | ||
str(jid) | ||
+ "_" | ||
+ str(strt.composition.reduced_formula) | ||
+ "_" | ||
+ j.to_dict()["symbol"] | ||
+ "_" | ||
+ j.to_dict()["wyckoff_multiplicity"] | ||
) | ||
print(name) | ||
def_energy = atom_to_energy(atoms=strt, model=model) * strt.num_atoms | ||
chem_pot = unary_energy(j.to_dict()["symbol"]) | ||
Ef = def_energy - (strt.num_atoms + 1) * bulk_en_pa + chem_pot | ||
print( | ||
j.to_dict()["symbol"], | ||
Ef, | ||
bulk_en_pa, | ||
def_energy, | ||
atoms.num_atoms, | ||
chem_pot, | ||
) | ||
|
||
|
||
get_defect_form_en() |
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 |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import torch | ||
from jarvis.core.atoms import Atoms | ||
from jarvis.core.graphs import Graph | ||
from alignn.models.alignn import ALIGNN | ||
# from jarvis.analysis.structure.spacegroup import Spacegroup3D | ||
from jarvis.db.figshare import data | ||
|
||
|
||
model_path = "JV15/jv_optb88vdw_bandgap_alignn/checkpoint_300.pt" | ||
device = "cpu" | ||
if torch.cuda.is_available(): | ||
device = torch.device("cuda") | ||
else: | ||
device = torch.device("cpu") | ||
model = ALIGNN() | ||
model.load_state_dict(torch.load(model_path, map_location=device)["model"]) | ||
# model=torch.load('checkpoint_250.pt')['model'] | ||
model.to(device) | ||
model.eval() | ||
|
||
|
||
def predict_for_db( | ||
name="polymer_genome", | ||
prop="gga_gap", | ||
filename="predictions.csv", | ||
id_tag="id", | ||
): | ||
db = data(name) | ||
filename = name + "_" + prop + "_v1_" + filename | ||
f = open(filename, "w") | ||
line = "id,original,out_data,num_atoms,formula,spacegroup_number\n" | ||
f.write(line) | ||
for i in db: | ||
src = i["source_folder"] | ||
if "vol" not in src: | ||
atoms = Atoms.from_dict(i["atoms"]) | ||
id = i[id_tag] | ||
|
||
g, lg = Graph.atom_dgl_multigraph(atoms) | ||
out_data = ( | ||
model([g.to(device), lg.to(device)]) | ||
.detach() | ||
.cpu() | ||
.numpy() | ||
.flatten() | ||
.tolist()[0] | ||
) | ||
original = i[prop] | ||
line = ( | ||
str(id) | ||
+ "," | ||
+ str(original) | ||
+ "," | ||
+ str(out_data) | ||
+ "," | ||
+ str(atoms.num_atoms) | ||
+ "," | ||
+ str(i["formula"]) | ||
+ "," | ||
+ str(i["spacegroup_number"]) | ||
+ str("\n") | ||
) | ||
f.write(line) | ||
# print (line) | ||
f.close() | ||
|
||
|
||
predict_for_db(name="qe_tb", prop="indir_gap", id_tag="jid") | ||
""" | ||
import pandas as pd | ||
df=pd.read_csv('qe_tb_indir_gap_predictions.csv') | ||
from sklearn.metrics import mean_absolute_error | ||
original=df['original'].values | ||
out_data=df['out_data'].values | ||
mae=mean_absolute_error(original,out_data) | ||
df['error']=abs(df['original']-df['out_data']) | ||
tol=0.5 | ||
df2=(df[df['error']>tol]) | ||
print (len(df2)) | ||
""" |
Oops, something went wrong.