Skip to content

Commit 37df129

Browse files
wangzyphysicsamcadmusfelix5572shazj99Zhengju Sha
authored
Calypso (#663)
* fix typo in github actions release to conda * Get from_poscar_path only when from_poscar is true (#537) Change-Id: I17774bee345634e4e72bd783e8112eefaaf9f0d3 Co-authored-by: Zhengju Sha <jenny@bytedance.com> * feature: merge run.py * fix:fix syntax bug * fix summary ratio bug * fix: fix bug of var(calypso_run_opt_path) not defined * reorganize code v1 * add: add unittest * add: add some explainations of dp+calypso in README.md * change a little bit in readme.md * change position of function * add deepmd-kit>=2.0.1 install_require in setup.py * test failed cause no tensorflow module so add tensorflow in setup.py * calc model devi in command line * fix some small bugs of modd and PBS script of cpu * fix unittest * delete parse_input.dat * fix unittest * first reorganization * secord reorganization * fix bugs * fix: fix bugs in modd_calypso.py write_modd.py and run.py * change functions name and fix bugs * remove modd_calypso.py * remove: remove modd_calypso.py * remove some useless outputs * restore dispatcher/PBS.py * refactor: make some changes in calypso related code - rename model_devi_calypso.py run_calypso.py - rename calypso.py make_calypso.py - add new file calypso_check_outcar.py calypso_run_opt.py - add new file calypso_run_model_devi.py - delete write_modd.py - modify README.md and run.py * refactor: move calypso main code(run.py) into run_calypso.py and modify test_calypso.py * docs: modify README.md related to CALYPSO * delete some useless comments in run.py * add write_model_devi_out function into make_calypso.py for passing unittest * fix a spelling mistake in calypso_run_opt.py (famx -> fmax) * change runopt script's name from run_opt.py to calypso_run_opt.py and fix bug in runopt script * fix unittest Co-authored-by: Han Wang <amcadmus@gmail.com> Co-authored-by: felix5572 <felix5572@github.com> Co-authored-by: shazj99 <shazj99@gmail.com> Co-authored-by: Zhengju Sha <jenny@bytedance.com> Co-authored-by: Han Wang <wang_han@iapcm.ac.cn>
1 parent ff77dc6 commit 37df129

File tree

12 files changed

+1336
-23
lines changed

12 files changed

+1336
-23
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,4 @@ dbconfig.json
4040
.vscode/*
4141
.idea/*
4242
_build
43+
tests/generator/calypso_test_path

README.md

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ In each iteration, there are three stages of work, namely, `00.train 01.model_d
378378

379379
+ 00.train: DP-GEN will train several (default 4) models based on initial and generated data. The only difference between these models is the random seed for neural network initialization.
380380

381-
+ 01.model_devi : represent for model-deviation. DP-GEN will use models obtained from 00.train to run Molecular Dynamics(default LAMMPS). Larger deviation for structure properties (default is force of atoms) means less accuracy of the models. Using this criterion, a few fructures will be selected and put into next stage `02.fp` for more accurate calculation based on First Principles.
381+
+ 01.model_devi : represent for model-deviation. Model-deviation engine in `01.model_devi` can be chosen between Molecular Dynamics(LAMMPS and GROMACS) or Structures Prediction(CALYPSO). DP-GEN will use models obtained from 00.train to run Molecular Dynamics or to run structure optimization with ASE in CALYPSO. Larger deviation for structure properties (default is force of atoms) means less accuracy of the models. Using this criterion, a few structures will be selected and put into next stage `02.fp` for more accurate calculation based on First Principles.
382382

383383
+ 02.fp : Selected structures will be calculated by first principles methods(default VASP). DP-GEN will obtain some new data and put them together with initial data and data generated in previous iterations. After that a new training will be set up and DP-GEN will enter next iteration!
384384

@@ -615,6 +615,35 @@ The bold notation of key (such aas **type_map**) means that it's a necessary key
615615
| **user_fp_params** | Dict | |Parameters for cp2k calculation. find detail in manual.cp2k.org. only the kind section must be set before use. we assume that you have basic knowledge for cp2k input.
616616
| **external_input_path** | String | | Conflict with key:user_fp_params, use the template input provided by user, some rules should be followed, read the following text in detail.
617617

618+
One can choose the model-deviation engine by specifying the key `model_devi_engine`. If `model_devi_engine` is not specified, the default model-deviation engine will be LAMMPS.
619+
620+
There are some new keys needed to be added into `param` and `machine` if CALYPSO as model-deviation engine.
621+
622+
The bold notation of key (such as **calypso_path**) means that it's a necessary key.
623+
624+
Key | Type | Example | Discription |
625+
| :---------------- | :--------------------- | :-------------------------------------- | :-------------------------------------------------------------|
626+
| *in param file*
627+
| **model_devi_engine** | string | "calypso" | CALYPSO as model-deviation engine.|
628+
| **calypso_input_path** | string | "/home/zhenyu/workplace/debug" | The absolute path of CALYPSO input file named input.dat(PSTRESS and fmax should be included), when this keys exists, all the iters will use the same CALYPSO input file until reach the number of max iter specified by **model_devi_max_iter** and **model_devi_jobs** key will not work.|
629+
| **model_devi_max_iter** | int | 10 | The max iter number code can run, it works when **calypso_input_path** exists.|
630+
| **model_devi_jobs** | List of Dict | [{ "times":[3],"NameOfAtoms":["Al","Cu"],"NumberOfAtoms":[1,10],"NumberOfFormula":[1,2],"Volume":[300],"DistanceOfIon":[[ 1.48,1.44],[ 1.44,1.41]],"PsoRatio":[0.6],"PopSize":[5],"MaxStep":[3],"ICode":[1],"Split":"T"},...] | Settings for exploration in `01.model_devi`. Different number in `times` List means different iteration index and iterations mentioned in List wil use same CALYPSO parameters.|
631+
| **model_devi_jobs["times"]** | List of int | [0,1,2] | Different number in `times` List means different iteration index and iterations mentioned in List wil use same CALYPSO parameters.|
632+
| **model_devi_jobs["NameOfAtoms"]** | List of string |["Al","Cu"] | Parameter of CALYPSO input file, means the element species of structures to be generated. |
633+
| **model_devi_jobs["NumberOfAtoms"]** | List of int |[1,10] | Parameter of CALYPSO input file, means the number of atoms for each chemical species in one formula unit. |
634+
| **model_devi_jobs["NumberOfFormula"]** | List of int |[1,2] | Parameter of CALYPSO input file, means the range of formula unit per cell. |
635+
| **model_devi_jobs["Volume"]** | List of int |[300] | Parameter of CALYPSO input file, means the colume per formula unit(angstrom^3). |
636+
| **model_devi_jobs["DistanceOfIon"]** | List of float |[[ 1.48,1.44],[ 1.44,1.41]] | Parameter of CALYPSO input file, means minimal distance between atoms of each chemical species. Unit is in angstrom. |
637+
| **model_devi_jobs["PsoRatio"]** | List of float |[0.6] | Parameter of CALYPSO input file, means the proportion of the structures generated by PSO. |
638+
| **model_devi_jobs["PopSize"]** | List of int |[5] | Parameter of CALYPSO input file, means the number of structures to be generated in one step in CALYPSO. |
639+
| **model_devi_jobs["MaxStep"]** | List of int |[3] | Parameter of CALYPSO input file, means the number of max step in CALYPSO.|
640+
| **model_devi_jobs["ICode"]** | List of int |[13] | Parameter of CALYPSO input file, means the chosen of local optimization, 1 is vasp and 13 is ASE with dp. |
641+
| **model_devi_jobs["Split"]** | String |"T" | Parameter of CALYPSO input file, means that generating structures and optimizing structures are split into two parts, in dpgen workflow, Split must be T. |
642+
| **model_devi_jobs["PSTRESS"]** | List of float |[0.001] | Same as PSTRESS in INCAR. |
643+
| **model_devi_jobs["fmax"]** | List of float |[0.01] | The convergence criterion is that the force on all individual atoms should be less than *fmax*. |
644+
| *in machine file*
645+
| **model_devi["deepmdkit_python"]** | String | "/home/zhenyu/soft/deepmd-kit/bin/python" | A python path with deepmd package. |
646+
| **model_devi["calypso_path"]** | string | "/home/zhenyu/workplace/debug" | The absolute path of calypso.x.|
618647

619648
#### Rules for cp2k input at dictionary form
620649
Converting cp2k input is very simple as dictionary used to dpgen input. You just need follow some simple rule:
@@ -1352,7 +1381,7 @@ mem_limit | Interger | 16 | Maximal memory permitted to apply for the job.
13521381
| group_size | Integer | 5 | DP-GEN will put these jobs together in one submitting script.
13531382
| user_forward_files | List of str | ["/path_to/vdw_kernel.bindat"] | These files will be uploaded in each calculation task. You should make sure provide the path exists.
13541383
| user_backward_files | List of str | ["HILLS"] | Besides DP-GEN's normal output, these files will be downloaded after each calculation. You should make sure these files can be generated.
1355-
1384+
13561385
## Troubleshooting
13571386
1. The most common problem is whether two settings correspond with each other, including:
13581387
- The order of elements in `type_map` and `mass_map` and **`fp_pp_files`**.
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
4+
import numpy as np
5+
import os,sys,glob,time
6+
from deepmd.calculator import DP
7+
from ase.io import read
8+
9+
'''
10+
check if structure optimization worked well
11+
if not, this script will generate a fake outcar
12+
'''
13+
14+
def Get_Element_Num(elements):
15+
'''Using the Atoms.symples to Know Element&Num'''
16+
element = []
17+
ele = {}
18+
element.append(elements[0])
19+
for x in elements:
20+
if x not in element :
21+
element.append(x)
22+
for x in element:
23+
ele[x] = elements.count(x)
24+
return element, ele
25+
26+
def Write_Contcar(element, ele, lat, pos):
27+
'''Write CONTCAR'''
28+
f = open('CONTCAR','w')
29+
f.write('ASE-DPKit-FAILED-nan\n')
30+
f.write('1.0\n')
31+
for i in range(3):
32+
f.write('%15.10f %15.10f %15.10f\n' % tuple(lat[i]))
33+
for x in element:
34+
f.write(x + ' ')
35+
f.write('\n')
36+
for x in element:
37+
f.write(str(ele[x]) + ' ')
38+
f.write('\n')
39+
f.write('Direct\n')
40+
na = sum(ele.values())
41+
dpos = np.dot(pos,np.linalg.inv(lat))
42+
for i in range(na):
43+
f.write('%15.10f %15.10f %15.10f\n' % tuple(dpos[i]))
44+
45+
def Write_Outcar(element, ele, volume, lat, pos, ene, force, stress,pstress):
46+
'''Write OUTCAR'''
47+
f = open('OUTCAR','w')
48+
for x in element:
49+
f.write('VRHFIN =' + str(x) + '\n')
50+
f.write('ions per type =')
51+
for x in element:
52+
f.write('%5d' % ele[x])
53+
#f.write('\nvolume of cell :\n')
54+
f.write('\nDirection XX YY ZZ XY YZ ZX\n')
55+
f.write('in kB')
56+
f.write('%15.6f' % stress[0])
57+
f.write('%15.6f' % stress[1])
58+
f.write('%15.6f' % stress[2])
59+
f.write('%15.6f' % stress[3])
60+
f.write('%15.6f' % stress[4])
61+
f.write('%15.6f' % stress[5])
62+
f.write('\n')
63+
ext_pressure = np.sum(stress[0] + stress[1] + stress[2])/3.0 - pstress
64+
f.write('external pressure = %20.6f kB Pullay stress = %20.6f kB\n'% (ext_pressure, pstress))
65+
f.write('volume of cell : %20.6f\n' % volume)
66+
f.write('direct lattice vectors\n')
67+
for i in range(3):
68+
f.write('%10.6f %10.6f %10.6f\n' % tuple(lat[i]))
69+
f.write('POSITION TOTAL-FORCE(eV/Angst)\n')
70+
f.write('-------------------------------------------------------------------\n')
71+
na = sum(ele.values())
72+
for i in range(na):
73+
f.write('%15.6f %15.6f %15.6f' % tuple(pos[i]))
74+
f.write('%15.6f %15.6f %15.6f\n' % tuple(force[i]))
75+
f.write('-------------------------------------------------------------------\n')
76+
f.write('energy without entropy= %20.6f %20.6f\n' % (ene, ene))
77+
enthalpy = ene + pstress * volume / 1602.17733
78+
f.write('enthalpy is TOTEN = %20.6f %20.6f\n' % (enthalpy, enthalpy))
79+
80+
def check():
81+
82+
from deepmd.calculator import DP
83+
from ase.io import read
84+
model_path = sys.argv[1]
85+
Model_List = glob.glob('%s/graph*pb'%model_path)
86+
calc = DP(model='%s'%(Model_List[0])) # init the model before iteration
87+
88+
to_be_opti = read('POSCAR')
89+
to_be_opti.calc = calc
90+
# ---------------------------------
91+
# for failed outcar
92+
atoms_symbols_f = to_be_opti.get_chemical_symbols()
93+
element_f, ele_f = Get_Element_Num(atoms_symbols_f)
94+
atoms_vol_f = to_be_opti.get_volume()
95+
atoms_stress_f = to_be_opti.get_stress()
96+
atoms_stress_f = atoms_stress_f/(0.01*0.6242)
97+
atoms_lat_f = to_be_opti.cell
98+
atoms_pos_f = to_be_opti.positions
99+
atoms_force_f = to_be_opti.get_forces()
100+
atoms_ene_f = 610612509
101+
# ---------------------------------
102+
Write_Contcar(element_f, ele_f, atoms_lat_f, atoms_pos_f)
103+
Write_Outcar(element_f, ele_f, atoms_vol_f, atoms_lat_f, atoms_pos_f,atoms_ene_f, atoms_force_f, atoms_stress_f * -10.0, 0)
104+
105+
cwd = os.getcwd()
106+
if not os.path.exists(os.path.join(cwd,'OUTCAR')):
107+
check()

0 commit comments

Comments
 (0)