-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstr-predict.py
More file actions
75 lines (66 loc) · 2.61 KB
/
Copy pathstr-predict.py
File metadata and controls
75 lines (66 loc) · 2.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# %%
import numpy as np
#import pandas as pd
from ase.io import read,write
#import json
from ase import Atoms
from chgnet.model.model import CHGNet
from pymatgen.core import Structure
#from pymatgen.io.ase import AseAtomsAdaptor
from icet import (ClusterSpace, StructureContainer,
CrossValidationEstimator, ClusterExpansion)
#from icet.tools import map_structure_to_reference, ConvexHull, enumerate_structures
from icet.tools.structure_generation import occupy_structure_randomly
# %%
#from icet import ClusterSpace
prim = read('FeCuS2.vasp')
prim_symbols = prim.get_chemical_symbols()
chemical_symbols = []
for s in prim_symbols:
if s == 'Cu':
# allow Li or vacancy on Li sites
chemical_symbols.append(['Zn','Cu'])
#chemical_symbols.append(['Li','Mn','Ti','X'])
#chemical_symbols.append(['Li', 'X'])
# elif s == 'Ti':
# keep Ti fixed
# chemical_symbols.append(['Li','Mn','X'])
# elif s == 'O':
# chemical_symbols.append(['O','F'])
else:
# fallback: keep whatever is present
chemical_symbols.append([s])
print(chemical_symbols) # sanity check: order should match prim.get_chemical_symbols()
cs = ClusterSpace(structure=prim,
cutoffs=[12.0, 6.0, 4.0],
chemical_symbols=chemical_symbols,
symprec=1e-05,
position_tolerance=0.5)
print(cs) # should show active sublattices (A, B, ...) and list allowed species
# %%
supercell=prim #*[3,3,3]
# %%
target_concentration = {'A':{'Zn': 4/8, 'Cu':4/8}}#,'A':{'O':29/32,'F':3/32}}
chgnet = CHGNet.load()
f1=open("E_rand-chgnet.dat","a")
#element_to_remove = "X"
for i in range(1,5000):
occupy_structure_randomly(supercell, cluster_space=cs, target_concentrations=target_concentration)
# filtered_supercell = supercell[[atom.symbol not in element_to_remove for atom in supercell]]
# write("str-rand/str-rand-vac-{}.vasp".format(i),filtered_supercell,sort=True)
write("str-rand/str-rand-vac-{}.vasp".format(i),supercell,sort=True)
print(i)
structure2=Structure.from_file("str-rand/str-rand-vac-{}.vasp".format(i))
#write("str-rand/str-rand-{}.vasp".format(i),supercell,sort=True)
#print(i)
#structure=Structure.from_file("str-rand/str-rand-{}.vasp".format(i))
prediction = chgnet.predict_structure(structure2)
for key, unit in [
("energy", "eV/atom"),
# ("forces", "eV/A"),
# ("stress", "GPa"),
("magmom", "mu_B"),
]:
#print(f"CHGNet-predicted {key} ({unit}): {prediction[key[0]]}\n")
f1.write(f"CHGNet-predicted str {i} {key} ({unit}): {prediction[key[0]]}\n")
f1.close()