Skip to content

Commit c67777a

Browse files
authored
Merge pull request #348 from robinzyb/devel
read the cp2k fp input file provided by user
2 parents 17476d6 + 79277c3 commit c67777a

File tree

9 files changed

+455
-111
lines changed

9 files changed

+455
-111
lines changed

README.md

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,8 @@ The bold notation of key (such aas **type_map**) means that it's a necessary key
571571
|**fp_params["mixingweight"]** | Float| 0.05 | Proportion a of output Density Matrix to be used for the input Density Matrix of next SCF cycle (linear mixing).
572572
|**fp_params["NumberPulay"]** | Integer| 5 | Controls the Pulay convergence accelerator.
573573
| *fp_style == cp2k*
574-
| **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.
574+
| **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.
575+
| **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.
575576

576577

577578
#### Rules for cp2k input at dictionary form
@@ -609,9 +610,54 @@ Here are examples for setting:
609610
}
610611
}
611612
}
613+
```
614+
615+
#### Rules for use cp2k template input provided by user
616+
617+
See Full example template.inp and dpgen input parameter file in
618+
619+
`tests/generator/cp2k_make_fp_files/exinput/template.inp` and `tests/generator/param-mgo-cp2k-exinput.json`
620+
621+
Here is example for provide external input
622+
623+
```python
624+
{
625+
"_comment": " 02.fp ",
626+
"fp_style": "cp2k",
627+
"shuffle_poscar": false,
628+
"fp_task_max": 100,
629+
"fp_task_min": 10,
630+
"fp_pp_path": ".",
631+
"fp_pp_files": [],
632+
"external_input_path": "./cp2k_make_fp_files/exinput/template.inp",
633+
"_comment": " that's all
634+
}
612635
```
613636

637+
the following essential section should be provided in user template
614638

639+
```
640+
641+
&FORCE_EVAL
642+
# add this line if you need to fit virial
643+
STRESS_TENSOR ANALYTICAL
644+
&PRINT
645+
&FORCES ON
646+
&END FORCES
647+
# add this line if you need to fit virial
648+
&STRESS_TENSOR ON
649+
&END FORCES
650+
&END PRINT
651+
&SUBSYS
652+
&CELL
653+
ABC LEFT FOR DPGEN
654+
&END CELL
655+
&COORD
656+
@include coord.xyz
657+
&END COORD
658+
&END SUBSYS
659+
&END FORCE_EVAL
660+
```
615661

616662
## Test: Auto-test for Deep Generator
617663
### configure and param.json

dpgen/generator/lib/cp2k.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,4 +183,35 @@ def make_cp2k_xyz(sys_data):
183183

184184

185185

186+
def make_cp2k_input_from_external(sys_data, exinput_path):
187+
# read the input content as string
188+
with open(exinput_path, 'r') as f:
189+
exinput = f.readlines()
190+
191+
# find the ABC cell string
192+
for line_idx, line in enumerate(exinput):
193+
if 'ABC' in line:
194+
delete_cell_idx = line_idx
195+
delete_cell_line = line
196+
197+
# remove the useless CELL line
198+
exinput.remove(delete_cell_line)
199+
200+
# insert the cell information
201+
# covert cell to cell string
202+
cell = sys_data['cells'][0]
203+
cell = np.reshape(cell, [3,3])
204+
cell_a = np.array2string(cell[0,:])
205+
cell_a = cell_a[1:-1]
206+
cell_b = np.array2string(cell[1,:])
207+
cell_b = cell_b[1:-1]
208+
cell_c = np.array2string(cell[2,:])
209+
cell_c = cell_c[1:-1]
210+
211+
exinput.insert(delete_cell_idx, 'A ' + cell_a + '\n')
212+
exinput.insert(delete_cell_idx+1, 'B ' + cell_b + '\n')
213+
exinput.insert(delete_cell_idx+2, 'C ' + cell_c + '\n')
214+
215+
return ''.join(exinput)
216+
186217

0 commit comments

Comments
 (0)