Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- .gitattributes +2 -0
- 3_epc/displacements/group_8/errs.txt +0 -0
- 3_epc/displacements/group_8/nerrs.txt +0 -0
- 3_epc/displacements/group_8/nscf.in +261 -0
- 3_epc/displacements/group_8/nscf.out +0 -0
- 3_epc/displacements/group_8/pw2bgw.in +19 -0
- 3_epc/displacements/group_8/pw2bgw.out +57 -0
- 3_epc/displacements/group_8/reconstruction/aohamiltonian/element.dat +2 -0
- 3_epc/displacements/group_8/reconstruction/aohamiltonian/graph.pkl +3 -0
- 3_epc/displacements/group_8/reconstruction/aohamiltonian/hamiltonians.h5 +3 -0
- 3_epc/displacements/group_8/reconstruction/aohamiltonian/hamiltonians_pred.h5 +3 -0
- 3_epc/displacements/group_8/reconstruction/aohamiltonian/hamiltonians_pred_e3.h5 +3 -0
- 3_epc/displacements/group_8/reconstruction/aohamiltonian/info.json +1 -0
- 3_epc/displacements/group_8/reconstruction/aohamiltonian/lat.dat +3 -0
- 3_epc/displacements/group_8/reconstruction/aohamiltonian/orbital_types.dat +2 -0
- 3_epc/displacements/group_8/reconstruction/aohamiltonian/overlaps.h5 +3 -0
- 3_epc/displacements/group_8/reconstruction/aohamiltonian/pred_ham_std/config.ini +82 -0
- 3_epc/displacements/group_8/reconstruction/aohamiltonian/pred_ham_std/result.txt +87 -0
- 3_epc/displacements/group_8/reconstruction/aohamiltonian/pred_ham_std/src/deeph/__init__.py +10 -0
- 3_epc/displacements/group_8/reconstruction/aohamiltonian/pred_ham_std/src/deeph/data.py +217 -0
- 3_epc/displacements/group_8/reconstruction/aohamiltonian/pred_ham_std/src/deeph/default.ini +88 -0
- 3_epc/displacements/group_8/reconstruction/aohamiltonian/pred_ham_std/src/deeph/from_HermNet/__init__.py +1 -0
- 3_epc/displacements/group_8/reconstruction/aohamiltonian/pred_ham_std/src/deeph/from_HermNet/__pycache__/__init__.cpython-312.pyc +0 -0
- 3_epc/displacements/group_8/reconstruction/aohamiltonian/pred_ham_std/src/deeph/from_HermNet/__pycache__/rmnet.cpython-312.pyc +0 -0
- 3_epc/displacements/group_8/reconstruction/aohamiltonian/pred_ham_std/src/deeph/from_HermNet/license.txt +1 -0
- 3_epc/displacements/group_8/reconstruction/aohamiltonian/pred_ham_std/src/deeph/from_HermNet/rmnet.py +105 -0
- 3_epc/displacements/group_8/reconstruction/aohamiltonian/pred_ham_std/src/deeph/from_PyG_future/__init__.py +2 -0
- 3_epc/displacements/group_8/reconstruction/aohamiltonian/pred_ham_std/src/deeph/from_PyG_future/__pycache__/__init__.cpython-312.pyc +0 -0
- 3_epc/displacements/group_8/reconstruction/aohamiltonian/pred_ham_std/src/deeph/from_PyG_future/__pycache__/diff_group_norm.cpython-312.pyc +0 -0
- 3_epc/displacements/group_8/reconstruction/aohamiltonian/pred_ham_std/src/deeph/from_PyG_future/__pycache__/graph_norm.cpython-312.pyc +0 -0
- 3_epc/displacements/group_8/reconstruction/aohamiltonian/pred_ham_std/src/deeph/from_PyG_future/diff_group_norm.py +109 -0
- 3_epc/displacements/group_8/reconstruction/aohamiltonian/pred_ham_std/src/deeph/from_PyG_future/graph_norm.py +60 -0
- 3_epc/displacements/group_8/reconstruction/aohamiltonian/pred_ham_std/src/deeph/from_PyG_future/license.txt +22 -0
- 3_epc/displacements/group_8/reconstruction/aohamiltonian/pred_ham_std/src/deeph/from_pymatgen/__init__.py +1 -0
- 3_epc/displacements/group_8/reconstruction/aohamiltonian/pred_ham_std/src/deeph/from_pymatgen/__pycache__/__init__.cpython-312.pyc +0 -0
- 3_epc/displacements/group_8/reconstruction/aohamiltonian/pred_ham_std/src/deeph/from_pymatgen/__pycache__/lattice.cpython-312.pyc +0 -0
- 3_epc/displacements/group_8/reconstruction/aohamiltonian/pred_ham_std/src/deeph/from_pymatgen/lattice.py +71 -0
- 3_epc/displacements/group_8/reconstruction/aohamiltonian/pred_ham_std/src/deeph/from_pymatgen/license.txt +22 -0
- 3_epc/displacements/group_8/reconstruction/aohamiltonian/pred_ham_std/src/deeph/from_schnetpack/__init__.py +1 -0
- 3_epc/displacements/group_8/reconstruction/aohamiltonian/pred_ham_std/src/deeph/from_schnetpack/__pycache__/__init__.cpython-312.pyc +0 -0
- 3_epc/displacements/group_8/reconstruction/aohamiltonian/pred_ham_std/src/deeph/from_schnetpack/__pycache__/acsf.cpython-312.pyc +0 -0
- 3_epc/displacements/group_8/reconstruction/aohamiltonian/pred_ham_std/src/deeph/from_schnetpack/acsf.py +50 -0
- 3_epc/displacements/group_8/reconstruction/aohamiltonian/pred_ham_std/src/deeph/from_schnetpack/license.txt +35 -0
- 3_epc/displacements/group_8/reconstruction/aohamiltonian/pred_ham_std/src/deeph/graph.py +934 -0
- 3_epc/displacements/group_8/reconstruction/aohamiltonian/pred_ham_std/src/deeph/kernel.py +844 -0
- 3_epc/displacements/group_8/reconstruction/aohamiltonian/pred_ham_std/src/deeph/model.py +676 -0
- 3_epc/displacements/group_8/reconstruction/aohamiltonian/pred_ham_std/src/deeph/preprocess/__init__.py +4 -0
- 3_epc/displacements/group_8/reconstruction/aohamiltonian/pred_ham_std/src/deeph/preprocess/__pycache__/abacus_get_data.cpython-312.pyc +0 -0
- 3_epc/displacements/group_8/reconstruction/aohamiltonian/pred_ham_std/src/deeph/preprocess/__pycache__/get_rc.cpython-312.pyc +0 -0
- 3_epc/displacements/group_8/reconstruction/aohamiltonian/pred_ham_std/src/deeph/preprocess/abacus_get_data.py +340 -0
.gitattributes
CHANGED
|
@@ -231,3 +231,5 @@ aobasis/siesta.DM filter=lfs diff=lfs merge=lfs -text
|
|
| 231 |
1_data_prepare/data/disp-07/scf/VSC filter=lfs diff=lfs merge=lfs -text
|
| 232 |
1_data_prepare/data/disp-07/scf/diamond.save/charge-density.dat filter=lfs diff=lfs merge=lfs -text
|
| 233 |
2_training/forces/diamond_ase_ref.nequip.pt2 filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
| 231 |
1_data_prepare/data/disp-07/scf/VSC filter=lfs diff=lfs merge=lfs -text
|
| 232 |
1_data_prepare/data/disp-07/scf/diamond.save/charge-density.dat filter=lfs diff=lfs merge=lfs -text
|
| 233 |
2_training/forces/diamond_ase_ref.nequip.pt2 filter=lfs diff=lfs merge=lfs -text
|
| 234 |
+
3_epc/displacements/group_8/tmp/VSC filter=lfs diff=lfs merge=lfs -text
|
| 235 |
+
3_epc/displacements/group_8/tmp/scf.save/charge-density.dat filter=lfs diff=lfs merge=lfs -text
|
3_epc/displacements/group_8/errs.txt
ADDED
|
File without changes
|
3_epc/displacements/group_8/nerrs.txt
ADDED
|
File without changes
|
3_epc/displacements/group_8/nscf.in
ADDED
|
@@ -0,0 +1,261 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
&CONTROL
|
| 2 |
+
calculation = 'nscf'
|
| 3 |
+
verbosity = 'high'
|
| 4 |
+
tstress = .false.
|
| 5 |
+
tprnfor = .true.
|
| 6 |
+
outdir = './tmp/'
|
| 7 |
+
prefix = 'scf'
|
| 8 |
+
pseudo_dir = '/home/apolyukhin/scripts/ml/diamond-qe/pseudos/'
|
| 9 |
+
/
|
| 10 |
+
&SYSTEM
|
| 11 |
+
ibrav = 0
|
| 12 |
+
nbnd = 8
|
| 13 |
+
ecutwfc = 60
|
| 14 |
+
nosym = .true.
|
| 15 |
+
noinv = .true.
|
| 16 |
+
ntyp = 1
|
| 17 |
+
nat = 2
|
| 18 |
+
/
|
| 19 |
+
&ELECTRONS
|
| 20 |
+
electron_maxstep = 1000
|
| 21 |
+
conv_thr = 1e-13
|
| 22 |
+
mixing_mode = 'plain'
|
| 23 |
+
mixing_beta = 0.7
|
| 24 |
+
diagonalization = 'david'
|
| 25 |
+
/
|
| 26 |
+
&IONS
|
| 27 |
+
/
|
| 28 |
+
&CELL
|
| 29 |
+
/
|
| 30 |
+
|
| 31 |
+
ATOMIC_SPECIES
|
| 32 |
+
C 12.011 C.upf
|
| 33 |
+
|
| 34 |
+
K_POINTS crystal
|
| 35 |
+
216
|
| 36 |
+
0.000000000000 0.000000000000 0.000000000000 4.62962963e-03
|
| 37 |
+
0.000000000000 0.000000000000 0.166666666667 4.62962963e-03
|
| 38 |
+
0.000000000000 0.000000000000 0.333333333333 4.62962963e-03
|
| 39 |
+
0.000000000000 0.000000000000 0.500000000000 4.62962963e-03
|
| 40 |
+
0.000000000000 0.000000000000 0.666666666667 4.62962963e-03
|
| 41 |
+
0.000000000000 0.000000000000 0.833333333333 4.62962963e-03
|
| 42 |
+
0.000000000000 0.166666666667 0.000000000000 4.62962963e-03
|
| 43 |
+
0.000000000000 0.166666666667 0.166666666667 4.62962963e-03
|
| 44 |
+
0.000000000000 0.166666666667 0.333333333333 4.62962963e-03
|
| 45 |
+
0.000000000000 0.166666666667 0.500000000000 4.62962963e-03
|
| 46 |
+
0.000000000000 0.166666666667 0.666666666667 4.62962963e-03
|
| 47 |
+
0.000000000000 0.166666666667 0.833333333333 4.62962963e-03
|
| 48 |
+
0.000000000000 0.333333333333 0.000000000000 4.62962963e-03
|
| 49 |
+
0.000000000000 0.333333333333 0.166666666667 4.62962963e-03
|
| 50 |
+
0.000000000000 0.333333333333 0.333333333333 4.62962963e-03
|
| 51 |
+
0.000000000000 0.333333333333 0.500000000000 4.62962963e-03
|
| 52 |
+
0.000000000000 0.333333333333 0.666666666667 4.62962963e-03
|
| 53 |
+
0.000000000000 0.333333333333 0.833333333333 4.62962963e-03
|
| 54 |
+
0.000000000000 0.500000000000 0.000000000000 4.62962963e-03
|
| 55 |
+
0.000000000000 0.500000000000 0.166666666667 4.62962963e-03
|
| 56 |
+
0.000000000000 0.500000000000 0.333333333333 4.62962963e-03
|
| 57 |
+
0.000000000000 0.500000000000 0.500000000000 4.62962963e-03
|
| 58 |
+
0.000000000000 0.500000000000 0.666666666667 4.62962963e-03
|
| 59 |
+
0.000000000000 0.500000000000 0.833333333333 4.62962963e-03
|
| 60 |
+
0.000000000000 0.666666666667 0.000000000000 4.62962963e-03
|
| 61 |
+
0.000000000000 0.666666666667 0.166666666667 4.62962963e-03
|
| 62 |
+
0.000000000000 0.666666666667 0.333333333333 4.62962963e-03
|
| 63 |
+
0.000000000000 0.666666666667 0.500000000000 4.62962963e-03
|
| 64 |
+
0.000000000000 0.666666666667 0.666666666667 4.62962963e-03
|
| 65 |
+
0.000000000000 0.666666666667 0.833333333333 4.62962963e-03
|
| 66 |
+
0.000000000000 0.833333333333 0.000000000000 4.62962963e-03
|
| 67 |
+
0.000000000000 0.833333333333 0.166666666667 4.62962963e-03
|
| 68 |
+
0.000000000000 0.833333333333 0.333333333333 4.62962963e-03
|
| 69 |
+
0.000000000000 0.833333333333 0.500000000000 4.62962963e-03
|
| 70 |
+
0.000000000000 0.833333333333 0.666666666667 4.62962963e-03
|
| 71 |
+
0.000000000000 0.833333333333 0.833333333333 4.62962963e-03
|
| 72 |
+
0.166666666667 0.000000000000 0.000000000000 4.62962963e-03
|
| 73 |
+
0.166666666667 0.000000000000 0.166666666667 4.62962963e-03
|
| 74 |
+
0.166666666667 0.000000000000 0.333333333333 4.62962963e-03
|
| 75 |
+
0.166666666667 0.000000000000 0.500000000000 4.62962963e-03
|
| 76 |
+
0.166666666667 0.000000000000 0.666666666667 4.62962963e-03
|
| 77 |
+
0.166666666667 0.000000000000 0.833333333333 4.62962963e-03
|
| 78 |
+
0.166666666667 0.166666666667 0.000000000000 4.62962963e-03
|
| 79 |
+
0.166666666667 0.166666666667 0.166666666667 4.62962963e-03
|
| 80 |
+
0.166666666667 0.166666666667 0.333333333333 4.62962963e-03
|
| 81 |
+
0.166666666667 0.166666666667 0.500000000000 4.62962963e-03
|
| 82 |
+
0.166666666667 0.166666666667 0.666666666667 4.62962963e-03
|
| 83 |
+
0.166666666667 0.166666666667 0.833333333333 4.62962963e-03
|
| 84 |
+
0.166666666667 0.333333333333 0.000000000000 4.62962963e-03
|
| 85 |
+
0.166666666667 0.333333333333 0.166666666667 4.62962963e-03
|
| 86 |
+
0.166666666667 0.333333333333 0.333333333333 4.62962963e-03
|
| 87 |
+
0.166666666667 0.333333333333 0.500000000000 4.62962963e-03
|
| 88 |
+
0.166666666667 0.333333333333 0.666666666667 4.62962963e-03
|
| 89 |
+
0.166666666667 0.333333333333 0.833333333333 4.62962963e-03
|
| 90 |
+
0.166666666667 0.500000000000 0.000000000000 4.62962963e-03
|
| 91 |
+
0.166666666667 0.500000000000 0.166666666667 4.62962963e-03
|
| 92 |
+
0.166666666667 0.500000000000 0.333333333333 4.62962963e-03
|
| 93 |
+
0.166666666667 0.500000000000 0.500000000000 4.62962963e-03
|
| 94 |
+
0.166666666667 0.500000000000 0.666666666667 4.62962963e-03
|
| 95 |
+
0.166666666667 0.500000000000 0.833333333333 4.62962963e-03
|
| 96 |
+
0.166666666667 0.666666666667 0.000000000000 4.62962963e-03
|
| 97 |
+
0.166666666667 0.666666666667 0.166666666667 4.62962963e-03
|
| 98 |
+
0.166666666667 0.666666666667 0.333333333333 4.62962963e-03
|
| 99 |
+
0.166666666667 0.666666666667 0.500000000000 4.62962963e-03
|
| 100 |
+
0.166666666667 0.666666666667 0.666666666667 4.62962963e-03
|
| 101 |
+
0.166666666667 0.666666666667 0.833333333333 4.62962963e-03
|
| 102 |
+
0.166666666667 0.833333333333 0.000000000000 4.62962963e-03
|
| 103 |
+
0.166666666667 0.833333333333 0.166666666667 4.62962963e-03
|
| 104 |
+
0.166666666667 0.833333333333 0.333333333333 4.62962963e-03
|
| 105 |
+
0.166666666667 0.833333333333 0.500000000000 4.62962963e-03
|
| 106 |
+
0.166666666667 0.833333333333 0.666666666667 4.62962963e-03
|
| 107 |
+
0.166666666667 0.833333333333 0.833333333333 4.62962963e-03
|
| 108 |
+
0.333333333333 0.000000000000 0.000000000000 4.62962963e-03
|
| 109 |
+
0.333333333333 0.000000000000 0.166666666667 4.62962963e-03
|
| 110 |
+
0.333333333333 0.000000000000 0.333333333333 4.62962963e-03
|
| 111 |
+
0.333333333333 0.000000000000 0.500000000000 4.62962963e-03
|
| 112 |
+
0.333333333333 0.000000000000 0.666666666667 4.62962963e-03
|
| 113 |
+
0.333333333333 0.000000000000 0.833333333333 4.62962963e-03
|
| 114 |
+
0.333333333333 0.166666666667 0.000000000000 4.62962963e-03
|
| 115 |
+
0.333333333333 0.166666666667 0.166666666667 4.62962963e-03
|
| 116 |
+
0.333333333333 0.166666666667 0.333333333333 4.62962963e-03
|
| 117 |
+
0.333333333333 0.166666666667 0.500000000000 4.62962963e-03
|
| 118 |
+
0.333333333333 0.166666666667 0.666666666667 4.62962963e-03
|
| 119 |
+
0.333333333333 0.166666666667 0.833333333333 4.62962963e-03
|
| 120 |
+
0.333333333333 0.333333333333 0.000000000000 4.62962963e-03
|
| 121 |
+
0.333333333333 0.333333333333 0.166666666667 4.62962963e-03
|
| 122 |
+
0.333333333333 0.333333333333 0.333333333333 4.62962963e-03
|
| 123 |
+
0.333333333333 0.333333333333 0.500000000000 4.62962963e-03
|
| 124 |
+
0.333333333333 0.333333333333 0.666666666667 4.62962963e-03
|
| 125 |
+
0.333333333333 0.333333333333 0.833333333333 4.62962963e-03
|
| 126 |
+
0.333333333333 0.500000000000 0.000000000000 4.62962963e-03
|
| 127 |
+
0.333333333333 0.500000000000 0.166666666667 4.62962963e-03
|
| 128 |
+
0.333333333333 0.500000000000 0.333333333333 4.62962963e-03
|
| 129 |
+
0.333333333333 0.500000000000 0.500000000000 4.62962963e-03
|
| 130 |
+
0.333333333333 0.500000000000 0.666666666667 4.62962963e-03
|
| 131 |
+
0.333333333333 0.500000000000 0.833333333333 4.62962963e-03
|
| 132 |
+
0.333333333333 0.666666666667 0.000000000000 4.62962963e-03
|
| 133 |
+
0.333333333333 0.666666666667 0.166666666667 4.62962963e-03
|
| 134 |
+
0.333333333333 0.666666666667 0.333333333333 4.62962963e-03
|
| 135 |
+
0.333333333333 0.666666666667 0.500000000000 4.62962963e-03
|
| 136 |
+
0.333333333333 0.666666666667 0.666666666667 4.62962963e-03
|
| 137 |
+
0.333333333333 0.666666666667 0.833333333333 4.62962963e-03
|
| 138 |
+
0.333333333333 0.833333333333 0.000000000000 4.62962963e-03
|
| 139 |
+
0.333333333333 0.833333333333 0.166666666667 4.62962963e-03
|
| 140 |
+
0.333333333333 0.833333333333 0.333333333333 4.62962963e-03
|
| 141 |
+
0.333333333333 0.833333333333 0.500000000000 4.62962963e-03
|
| 142 |
+
0.333333333333 0.833333333333 0.666666666667 4.62962963e-03
|
| 143 |
+
0.333333333333 0.833333333333 0.833333333333 4.62962963e-03
|
| 144 |
+
0.500000000000 0.000000000000 0.000000000000 4.62962963e-03
|
| 145 |
+
0.500000000000 0.000000000000 0.166666666667 4.62962963e-03
|
| 146 |
+
0.500000000000 0.000000000000 0.333333333333 4.62962963e-03
|
| 147 |
+
0.500000000000 0.000000000000 0.500000000000 4.62962963e-03
|
| 148 |
+
0.500000000000 0.000000000000 0.666666666667 4.62962963e-03
|
| 149 |
+
0.500000000000 0.000000000000 0.833333333333 4.62962963e-03
|
| 150 |
+
0.500000000000 0.166666666667 0.000000000000 4.62962963e-03
|
| 151 |
+
0.500000000000 0.166666666667 0.166666666667 4.62962963e-03
|
| 152 |
+
0.500000000000 0.166666666667 0.333333333333 4.62962963e-03
|
| 153 |
+
0.500000000000 0.166666666667 0.500000000000 4.62962963e-03
|
| 154 |
+
0.500000000000 0.166666666667 0.666666666667 4.62962963e-03
|
| 155 |
+
0.500000000000 0.166666666667 0.833333333333 4.62962963e-03
|
| 156 |
+
0.500000000000 0.333333333333 0.000000000000 4.62962963e-03
|
| 157 |
+
0.500000000000 0.333333333333 0.166666666667 4.62962963e-03
|
| 158 |
+
0.500000000000 0.333333333333 0.333333333333 4.62962963e-03
|
| 159 |
+
0.500000000000 0.333333333333 0.500000000000 4.62962963e-03
|
| 160 |
+
0.500000000000 0.333333333333 0.666666666667 4.62962963e-03
|
| 161 |
+
0.500000000000 0.333333333333 0.833333333333 4.62962963e-03
|
| 162 |
+
0.500000000000 0.500000000000 0.000000000000 4.62962963e-03
|
| 163 |
+
0.500000000000 0.500000000000 0.166666666667 4.62962963e-03
|
| 164 |
+
0.500000000000 0.500000000000 0.333333333333 4.62962963e-03
|
| 165 |
+
0.500000000000 0.500000000000 0.500000000000 4.62962963e-03
|
| 166 |
+
0.500000000000 0.500000000000 0.666666666667 4.62962963e-03
|
| 167 |
+
0.500000000000 0.500000000000 0.833333333333 4.62962963e-03
|
| 168 |
+
0.500000000000 0.666666666667 0.000000000000 4.62962963e-03
|
| 169 |
+
0.500000000000 0.666666666667 0.166666666667 4.62962963e-03
|
| 170 |
+
0.500000000000 0.666666666667 0.333333333333 4.62962963e-03
|
| 171 |
+
0.500000000000 0.666666666667 0.500000000000 4.62962963e-03
|
| 172 |
+
0.500000000000 0.666666666667 0.666666666667 4.62962963e-03
|
| 173 |
+
0.500000000000 0.666666666667 0.833333333333 4.62962963e-03
|
| 174 |
+
0.500000000000 0.833333333333 0.000000000000 4.62962963e-03
|
| 175 |
+
0.500000000000 0.833333333333 0.166666666667 4.62962963e-03
|
| 176 |
+
0.500000000000 0.833333333333 0.333333333333 4.62962963e-03
|
| 177 |
+
0.500000000000 0.833333333333 0.500000000000 4.62962963e-03
|
| 178 |
+
0.500000000000 0.833333333333 0.666666666667 4.62962963e-03
|
| 179 |
+
0.500000000000 0.833333333333 0.833333333333 4.62962963e-03
|
| 180 |
+
0.666666666667 0.000000000000 0.000000000000 4.62962963e-03
|
| 181 |
+
0.666666666667 0.000000000000 0.166666666667 4.62962963e-03
|
| 182 |
+
0.666666666667 0.000000000000 0.333333333333 4.62962963e-03
|
| 183 |
+
0.666666666667 0.000000000000 0.500000000000 4.62962963e-03
|
| 184 |
+
0.666666666667 0.000000000000 0.666666666667 4.62962963e-03
|
| 185 |
+
0.666666666667 0.000000000000 0.833333333333 4.62962963e-03
|
| 186 |
+
0.666666666667 0.166666666667 0.000000000000 4.62962963e-03
|
| 187 |
+
0.666666666667 0.166666666667 0.166666666667 4.62962963e-03
|
| 188 |
+
0.666666666667 0.166666666667 0.333333333333 4.62962963e-03
|
| 189 |
+
0.666666666667 0.166666666667 0.500000000000 4.62962963e-03
|
| 190 |
+
0.666666666667 0.166666666667 0.666666666667 4.62962963e-03
|
| 191 |
+
0.666666666667 0.166666666667 0.833333333333 4.62962963e-03
|
| 192 |
+
0.666666666667 0.333333333333 0.000000000000 4.62962963e-03
|
| 193 |
+
0.666666666667 0.333333333333 0.166666666667 4.62962963e-03
|
| 194 |
+
0.666666666667 0.333333333333 0.333333333333 4.62962963e-03
|
| 195 |
+
0.666666666667 0.333333333333 0.500000000000 4.62962963e-03
|
| 196 |
+
0.666666666667 0.333333333333 0.666666666667 4.62962963e-03
|
| 197 |
+
0.666666666667 0.333333333333 0.833333333333 4.62962963e-03
|
| 198 |
+
0.666666666667 0.500000000000 0.000000000000 4.62962963e-03
|
| 199 |
+
0.666666666667 0.500000000000 0.166666666667 4.62962963e-03
|
| 200 |
+
0.666666666667 0.500000000000 0.333333333333 4.62962963e-03
|
| 201 |
+
0.666666666667 0.500000000000 0.500000000000 4.62962963e-03
|
| 202 |
+
0.666666666667 0.500000000000 0.666666666667 4.62962963e-03
|
| 203 |
+
0.666666666667 0.500000000000 0.833333333333 4.62962963e-03
|
| 204 |
+
0.666666666667 0.666666666667 0.000000000000 4.62962963e-03
|
| 205 |
+
0.666666666667 0.666666666667 0.166666666667 4.62962963e-03
|
| 206 |
+
0.666666666667 0.666666666667 0.333333333333 4.62962963e-03
|
| 207 |
+
0.666666666667 0.666666666667 0.500000000000 4.62962963e-03
|
| 208 |
+
0.666666666667 0.666666666667 0.666666666667 4.62962963e-03
|
| 209 |
+
0.666666666667 0.666666666667 0.833333333333 4.62962963e-03
|
| 210 |
+
0.666666666667 0.833333333333 0.000000000000 4.62962963e-03
|
| 211 |
+
0.666666666667 0.833333333333 0.166666666667 4.62962963e-03
|
| 212 |
+
0.666666666667 0.833333333333 0.333333333333 4.62962963e-03
|
| 213 |
+
0.666666666667 0.833333333333 0.500000000000 4.62962963e-03
|
| 214 |
+
0.666666666667 0.833333333333 0.666666666667 4.62962963e-03
|
| 215 |
+
0.666666666667 0.833333333333 0.833333333333 4.62962963e-03
|
| 216 |
+
0.833333333333 0.000000000000 0.000000000000 4.62962963e-03
|
| 217 |
+
0.833333333333 0.000000000000 0.166666666667 4.62962963e-03
|
| 218 |
+
0.833333333333 0.000000000000 0.333333333333 4.62962963e-03
|
| 219 |
+
0.833333333333 0.000000000000 0.500000000000 4.62962963e-03
|
| 220 |
+
0.833333333333 0.000000000000 0.666666666667 4.62962963e-03
|
| 221 |
+
0.833333333333 0.000000000000 0.833333333333 4.62962963e-03
|
| 222 |
+
0.833333333333 0.166666666667 0.000000000000 4.62962963e-03
|
| 223 |
+
0.833333333333 0.166666666667 0.166666666667 4.62962963e-03
|
| 224 |
+
0.833333333333 0.166666666667 0.333333333333 4.62962963e-03
|
| 225 |
+
0.833333333333 0.166666666667 0.500000000000 4.62962963e-03
|
| 226 |
+
0.833333333333 0.166666666667 0.666666666667 4.62962963e-03
|
| 227 |
+
0.833333333333 0.166666666667 0.833333333333 4.62962963e-03
|
| 228 |
+
0.833333333333 0.333333333333 0.000000000000 4.62962963e-03
|
| 229 |
+
0.833333333333 0.333333333333 0.166666666667 4.62962963e-03
|
| 230 |
+
0.833333333333 0.333333333333 0.333333333333 4.62962963e-03
|
| 231 |
+
0.833333333333 0.333333333333 0.500000000000 4.62962963e-03
|
| 232 |
+
0.833333333333 0.333333333333 0.666666666667 4.62962963e-03
|
| 233 |
+
0.833333333333 0.333333333333 0.833333333333 4.62962963e-03
|
| 234 |
+
0.833333333333 0.500000000000 0.000000000000 4.62962963e-03
|
| 235 |
+
0.833333333333 0.500000000000 0.166666666667 4.62962963e-03
|
| 236 |
+
0.833333333333 0.500000000000 0.333333333333 4.62962963e-03
|
| 237 |
+
0.833333333333 0.500000000000 0.500000000000 4.62962963e-03
|
| 238 |
+
0.833333333333 0.500000000000 0.666666666667 4.62962963e-03
|
| 239 |
+
0.833333333333 0.500000000000 0.833333333333 4.62962963e-03
|
| 240 |
+
0.833333333333 0.666666666667 0.000000000000 4.62962963e-03
|
| 241 |
+
0.833333333333 0.666666666667 0.166666666667 4.62962963e-03
|
| 242 |
+
0.833333333333 0.666666666667 0.333333333333 4.62962963e-03
|
| 243 |
+
0.833333333333 0.666666666667 0.500000000000 4.62962963e-03
|
| 244 |
+
0.833333333333 0.666666666667 0.666666666667 4.62962963e-03
|
| 245 |
+
0.833333333333 0.666666666667 0.833333333333 4.62962963e-03
|
| 246 |
+
0.833333333333 0.833333333333 0.000000000000 4.62962963e-03
|
| 247 |
+
0.833333333333 0.833333333333 0.166666666667 4.62962963e-03
|
| 248 |
+
0.833333333333 0.833333333333 0.333333333333 4.62962963e-03
|
| 249 |
+
0.833333333333 0.833333333333 0.500000000000 4.62962963e-03
|
| 250 |
+
0.833333333333 0.833333333333 0.666666666667 4.62962963e-03
|
| 251 |
+
0.833333333333 0.833333333333 0.833333333333 4.62962963e-03
|
| 252 |
+
|
| 253 |
+
CELL_PARAMETERS angstrom
|
| 254 |
+
0.00000000000000 1.78350000000000 1.78350000000000
|
| 255 |
+
1.78350000000000 0.00000000000000 1.78350000000000
|
| 256 |
+
1.78350000000000 1.78350000000000 0.00000000000000
|
| 257 |
+
|
| 258 |
+
ATOMIC_POSITIONS crystal
|
| 259 |
+
C 0.0000000000 0.0000000000 -0.0000000000
|
| 260 |
+
C 0.2497901964 0.2500000000 0.2500000000
|
| 261 |
+
|
3_epc/displacements/group_8/nscf.out
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
3_epc/displacements/group_8/pw2bgw.in
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
&input_pw2bgw
|
| 2 |
+
prefix = 'scf'
|
| 3 |
+
outdir = './tmp/'
|
| 4 |
+
real_or_complex = 2
|
| 5 |
+
wfng_flag = .false.
|
| 6 |
+
wfng_file = 'WFN'
|
| 7 |
+
wfng_kgrid = .true.
|
| 8 |
+
wfng_nk1 = 6
|
| 9 |
+
wfng_nk2 = 6
|
| 10 |
+
wfng_nk3 = 6
|
| 11 |
+
wfng_dk1 = 0.0
|
| 12 |
+
wfng_dk2 = 0.0
|
| 13 |
+
wfng_dk3 = 0.0
|
| 14 |
+
rhog_flag = .false.
|
| 15 |
+
vxcg_flag = .false.
|
| 16 |
+
vscg_flag = .true.
|
| 17 |
+
vscg_file = 'VSC'
|
| 18 |
+
vkbg_flag = .false.
|
| 19 |
+
/
|
3_epc/displacements/group_8/pw2bgw.out
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
Program PW2BGW v.7.2 starts on 19Feb2026 at 20:59:32
|
| 3 |
+
|
| 4 |
+
This program is part of the open-source Quantum ESPRESSO suite
|
| 5 |
+
for quantum simulation of materials; please cite
|
| 6 |
+
"P. Giannozzi et al., J. Phys.:Condens. Matter 21 395502 (2009);
|
| 7 |
+
"P. Giannozzi et al., J. Phys.:Condens. Matter 29 465901 (2017);
|
| 8 |
+
"P. Giannozzi et al., J. Chem. Phys. 152 154105 (2020);
|
| 9 |
+
URL http://www.quantum-espresso.org",
|
| 10 |
+
in publications or presentations arising from this work. More details at
|
| 11 |
+
http://www.quantum-espresso.org/quote
|
| 12 |
+
|
| 13 |
+
Parallel version (MPI), running on 8 processors
|
| 14 |
+
|
| 15 |
+
MPI processes distributed on 1 nodes
|
| 16 |
+
R & G space division: proc/nbgrp/npool/nimage = 8
|
| 17 |
+
1126 MiB available memory on the printing compute node when the environment starts
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
Reading xml data from directory:
|
| 21 |
+
|
| 22 |
+
./tmp/scf.save/
|
| 23 |
+
|
| 24 |
+
IMPORTANT: XC functional enforced from input :
|
| 25 |
+
Exchange-correlation= PBE
|
| 26 |
+
( 1 4 3 4 0 0 0)
|
| 27 |
+
Any further DFT definition will be discarded
|
| 28 |
+
Please, verify this is what you really want
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
Parallelization info
|
| 32 |
+
--------------------
|
| 33 |
+
sticks: dense smooth PW G-vecs: dense smooth PW
|
| 34 |
+
Min 47 47 16 613 613 129
|
| 35 |
+
Max 48 48 18 615 615 130
|
| 36 |
+
Sum 379 379 139 4909 4909 1037
|
| 37 |
+
|
| 38 |
+
Using Slab Decomposition
|
| 39 |
+
|
| 40 |
+
Reading collected, re-writing distributed wavefunctions
|
| 41 |
+
|
| 42 |
+
NLCC is present
|
| 43 |
+
|
| 44 |
+
call write_vscg
|
| 45 |
+
done write_vscg
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
write_vscg : 0.00s CPU 0.00s WALL ( 1 calls)
|
| 49 |
+
|
| 50 |
+
PW2BGW : 0.09s CPU 0.11s WALL
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
This run was terminated on: 20:59:33 19Feb2026
|
| 54 |
+
|
| 55 |
+
=------------------------------------------------------------------------------=
|
| 56 |
+
JOB DONE.
|
| 57 |
+
=------------------------------------------------------------------------------=
|
3_epc/displacements/group_8/reconstruction/aohamiltonian/element.dat
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
6
|
| 2 |
+
6
|
3_epc/displacements/group_8/reconstruction/aohamiltonian/graph.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:57b03f08d23ccc2b37c2fd9890e51cc54f31a7fffde5b6a5ecfc404672eb6677
|
| 3 |
+
size 8317809
|
3_epc/displacements/group_8/reconstruction/aohamiltonian/hamiltonians.h5
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:6a2e1daa19a8c118c77c7821fb5a4f445f3a91e8024f788c2f3658e6f2f172cf
|
| 3 |
+
size 558800
|
3_epc/displacements/group_8/reconstruction/aohamiltonian/hamiltonians_pred.h5
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:35780389a9aede62f61f71b0d9bc2dce23f4a5d36165d2acbfb1c85e86ab968d
|
| 3 |
+
size 519600
|
3_epc/displacements/group_8/reconstruction/aohamiltonian/hamiltonians_pred_e3.h5
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:223c864268168496cae262546e7cced2cb289e90f359ecc9bb6a3ef623b5b447
|
| 3 |
+
size 349388
|
3_epc/displacements/group_8/reconstruction/aohamiltonian/info.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"isspinful": false}
|
3_epc/displacements/group_8/reconstruction/aohamiltonian/lat.dat
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
0.000000000000000000e+00 1.783499998856923785e+00 1.783499998856923785e+00
|
| 2 |
+
1.783499998856923785e+00 0.000000000000000000e+00 1.783499998856923785e+00
|
| 3 |
+
1.783499998856923785e+00 1.783499998856923785e+00 0.000000000000000000e+00
|
3_epc/displacements/group_8/reconstruction/aohamiltonian/orbital_types.dat
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
0 0 1 1 2
|
| 2 |
+
0 0 1 1 2
|
3_epc/displacements/group_8/reconstruction/aohamiltonian/overlaps.h5
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:2767c43fa547964ee5bf27eb4e04698b63d2bbf818d1bde10f5d0830388a0922
|
| 3 |
+
size 499888
|
3_epc/displacements/group_8/reconstruction/aohamiltonian/pred_ham_std/config.ini
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[basic]
|
| 2 |
+
graph_dir = /home/apolyukhin/scripts/ml/diamond-qe/deeph-data/graph
|
| 3 |
+
save_dir = /home/apolyukhin/scripts/ml/diamond-qe/diamond_epc/displacements/group_8/reconstruction/aohamiltonian/pred_ham_std
|
| 4 |
+
raw_dir = /home/apolyukhin/scripts/ml/diamond-qe/deeph-data/preprocess
|
| 5 |
+
dataset_name = diamond_qe
|
| 6 |
+
only_get_graph = False
|
| 7 |
+
interface = h5
|
| 8 |
+
target = hamiltonian
|
| 9 |
+
disable_cuda = True
|
| 10 |
+
device = cpu
|
| 11 |
+
num_threads = -1
|
| 12 |
+
save_to_time_folder = False
|
| 13 |
+
save_csv = True
|
| 14 |
+
tb_writer = False
|
| 15 |
+
seed = 42
|
| 16 |
+
multiprocessing = 0
|
| 17 |
+
orbital = [{"6 6": [0, 0]}, {"6 6": [0, 1]}, {"6 6": [0, 2]}, {"6 6": [0, 3]}, {"6 6": [0, 4]}, {"6 6": [0, 5]}, {"6 6": [0, 6]}, {"6 6": [0, 7]}, {"6 6": [0, 8]}, {"6 6": [0, 9]}, {"6 6": [0, 10]}, {"6 6": [0, 11]}, {"6 6": [0, 12]}, {"6 6": [1, 0]}, {"6 6": [1, 1]}, {"6 6": [1, 2]}, {"6 6": [1, 3]}, {"6 6": [1, 4]}, {"6 6": [1, 5]}, {"6 6": [1, 6]}, {"6 6": [1, 7]}, {"6 6": [1, 8]}, {"6 6": [1, 9]}, {"6 6": [1, 10]}, {"6 6": [1, 11]}, {"6 6": [1, 12]}, {"6 6": [2, 0]}, {"6 6": [2, 1]}, {"6 6": [2, 2]}, {"6 6": [2, 3]}, {"6 6": [2, 4]}, {"6 6": [2, 5]}, {"6 6": [2, 6]}, {"6 6": [2, 7]}, {"6 6": [2, 8]}, {"6 6": [2, 9]}, {"6 6": [2, 10]}, {"6 6": [2, 11]}, {"6 6": [2, 12]}, {"6 6": [3, 0]}, {"6 6": [3, 1]}, {"6 6": [3, 2]}, {"6 6": [3, 3]}, {"6 6": [3, 4]}, {"6 6": [3, 5]}, {"6 6": [3, 6]}, {"6 6": [3, 7]}, {"6 6": [3, 8]}, {"6 6": [3, 9]}, {"6 6": [3, 10]}, {"6 6": [3, 11]}, {"6 6": [3, 12]}, {"6 6": [4, 0]}, {"6 6": [4, 1]}, {"6 6": [4, 2]}, {"6 6": [4, 3]}, {"6 6": [4, 4]}, {"6 6": [4, 5]}, {"6 6": [4, 6]}, {"6 6": [4, 7]}, {"6 6": [4, 8]}, {"6 6": [4, 9]}, {"6 6": [4, 10]}, {"6 6": [4, 11]}, {"6 6": [4, 12]}, {"6 6": [5, 0]}, {"6 6": [5, 1]}, {"6 6": [5, 2]}, {"6 6": [5, 3]}, {"6 6": [5, 4]}, {"6 6": [5, 5]}, {"6 6": [5, 6]}, {"6 6": [5, 7]}, {"6 6": [5, 8]}, {"6 6": [5, 9]}, {"6 6": [5, 10]}, {"6 6": [5, 11]}, {"6 6": [5, 12]}, {"6 6": [6, 0]}, {"6 6": [6, 1]}, {"6 6": [6, 2]}, {"6 6": [6, 3]}, {"6 6": [6, 4]}, {"6 6": [6, 5]}, {"6 6": [6, 6]}, {"6 6": [6, 7]}, {"6 6": [6, 8]}, {"6 6": [6, 9]}, {"6 6": [6, 10]}, {"6 6": [6, 11]}, {"6 6": [6, 12]}, {"6 6": [7, 0]}, {"6 6": [7, 1]}, {"6 6": [7, 2]}, {"6 6": [7, 3]}, {"6 6": [7, 4]}, {"6 6": [7, 5]}, {"6 6": [7, 6]}, {"6 6": [7, 7]}, {"6 6": [7, 8]}, {"6 6": [7, 9]}, {"6 6": [7, 10]}, {"6 6": [7, 11]}, {"6 6": [7, 12]}, {"6 6": [8, 0]}, {"6 6": [8, 1]}, {"6 6": [8, 2]}, {"6 6": [8, 3]}, {"6 6": [8, 4]}, {"6 6": [8, 5]}, {"6 6": [8, 6]}, {"6 6": [8, 7]}, {"6 6": [8, 8]}, {"6 6": [8, 9]}, {"6 6": [8, 10]}, {"6 6": [8, 11]}, {"6 6": [8, 12]}, {"6 6": [9, 0]}, {"6 6": [9, 1]}, {"6 6": [9, 2]}, {"6 6": [9, 3]}, {"6 6": [9, 4]}, {"6 6": [9, 5]}, {"6 6": [9, 6]}, {"6 6": [9, 7]}, {"6 6": [9, 8]}, {"6 6": [9, 9]}, {"6 6": [9, 10]}, {"6 6": [9, 11]}, {"6 6": [9, 12]}, {"6 6": [10, 0]}, {"6 6": [10, 1]}, {"6 6": [10, 2]}, {"6 6": [10, 3]}, {"6 6": [10, 4]}, {"6 6": [10, 5]}, {"6 6": [10, 6]}, {"6 6": [10, 7]}, {"6 6": [10, 8]}, {"6 6": [10, 9]}, {"6 6": [10, 10]}, {"6 6": [10, 11]}, {"6 6": [10, 12]}, {"6 6": [11, 0]}, {"6 6": [11, 1]}, {"6 6": [11, 2]}, {"6 6": [11, 3]}, {"6 6": [11, 4]}, {"6 6": [11, 5]}, {"6 6": [11, 6]}, {"6 6": [11, 7]}, {"6 6": [11, 8]}, {"6 6": [11, 9]}, {"6 6": [11, 10]}, {"6 6": [11, 11]}, {"6 6": [11, 12]}, {"6 6": [12, 0]}, {"6 6": [12, 1]}, {"6 6": [12, 2]}, {"6 6": [12, 3]}, {"6 6": [12, 4]}, {"6 6": [12, 5]}, {"6 6": [12, 6]}, {"6 6": [12, 7]}, {"6 6": [12, 8]}, {"6 6": [12, 9]}, {"6 6": [12, 10]}, {"6 6": [12, 11]}, {"6 6": [12, 12]}]
|
| 18 |
+
o_component = H
|
| 19 |
+
energy_component = summation
|
| 20 |
+
max_element = -1
|
| 21 |
+
statistics = False
|
| 22 |
+
normalizer = False
|
| 23 |
+
boxcox = False
|
| 24 |
+
|
| 25 |
+
[graph]
|
| 26 |
+
radius = -1.0
|
| 27 |
+
max_num_nbr = 0
|
| 28 |
+
create_from_dft = True
|
| 29 |
+
if_lcmp_graph = True
|
| 30 |
+
separate_onsite = False
|
| 31 |
+
new_sp = False
|
| 32 |
+
|
| 33 |
+
[train]
|
| 34 |
+
epochs = 5000
|
| 35 |
+
pretrained =
|
| 36 |
+
resume =
|
| 37 |
+
train_ratio = 0.6
|
| 38 |
+
val_ratio = 0.2
|
| 39 |
+
test_ratio = 0.2
|
| 40 |
+
early_stopping_loss = 0.0
|
| 41 |
+
early_stopping_loss_epoch = [0.000000, 500]
|
| 42 |
+
revert_then_decay = True
|
| 43 |
+
revert_threshold = 30
|
| 44 |
+
revert_decay_epoch = [800, 2000, 3000, 4000]
|
| 45 |
+
revert_decay_gamma = [0.4, 0.5, 0.5, 0.4]
|
| 46 |
+
clip_grad = True
|
| 47 |
+
clip_grad_value = 4.2
|
| 48 |
+
switch_sgd = False
|
| 49 |
+
switch_sgd_lr = 1e-4
|
| 50 |
+
switch_sgd_epoch = -1
|
| 51 |
+
|
| 52 |
+
[hyperparameter]
|
| 53 |
+
batch_size = 1
|
| 54 |
+
dtype = float32
|
| 55 |
+
optimizer = adam
|
| 56 |
+
learning_rate = 0.001
|
| 57 |
+
lr_scheduler =
|
| 58 |
+
lr_milestones = []
|
| 59 |
+
momentum = 0.9
|
| 60 |
+
weight_decay = 0
|
| 61 |
+
criterion = MaskMSELoss
|
| 62 |
+
retain_edge_fea = True
|
| 63 |
+
lambda_eij = 0.0
|
| 64 |
+
lambda_ei = 0.1
|
| 65 |
+
lambda_etot = 0.0
|
| 66 |
+
|
| 67 |
+
[network]
|
| 68 |
+
atom_fea_len = 64
|
| 69 |
+
edge_fea_len = 128
|
| 70 |
+
gauss_stop = 6.0
|
| 71 |
+
num_l = 4
|
| 72 |
+
aggr = add
|
| 73 |
+
distance_expansion = GaussianBasis
|
| 74 |
+
if_exp = True
|
| 75 |
+
if_multiplelinear = False
|
| 76 |
+
if_edge_update = True
|
| 77 |
+
if_lcmp = True
|
| 78 |
+
normalization = LayerNorm
|
| 79 |
+
atom_update_net = PAINN
|
| 80 |
+
trainable_gaussians = False
|
| 81 |
+
type_affine = False
|
| 82 |
+
|
3_epc/displacements/group_8/reconstruction/aohamiltonian/pred_ham_std/result.txt
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 0 |
0%| | 0/1 [00:00<?, ?it/s]
|
|
|
|
| 1 |
+
====== CONFIG ======
|
| 2 |
+
[basic]
|
| 3 |
+
graph_dir=/home/apolyukhin/scripts/ml/diamond-qe/deeph-data/graph
|
| 4 |
+
save_dir=/home/apolyukhin/scripts/ml/diamond-qe/diamond_epc/displacements/group_8/reconstruction/aohamiltonian/pred_ham_std
|
| 5 |
+
raw_dir=/home/apolyukhin/scripts/ml/diamond-qe/deeph-data/preprocess
|
| 6 |
+
dataset_name=diamond_qe
|
| 7 |
+
only_get_graph=False
|
| 8 |
+
interface=h5
|
| 9 |
+
target=hamiltonian
|
| 10 |
+
disable_cuda=True
|
| 11 |
+
device=cpu
|
| 12 |
+
num_threads=-1
|
| 13 |
+
save_to_time_folder=False
|
| 14 |
+
save_csv=True
|
| 15 |
+
tb_writer=False
|
| 16 |
+
seed=42
|
| 17 |
+
multiprocessing=0
|
| 18 |
+
orbital=[{"6 6": [0, 0]}, {"6 6": [0, 1]}, {"6 6": [0, 2]}, {"6 6": [0, 3]}, {"6 6": [0, 4]}, {"6 6": [0, 5]}, {"6 6": [0, 6]}, {"6 6": [0, 7]}, {"6 6": [0, 8]}, {"6 6": [0, 9]}, {"6 6": [0, 10]}, {"6 6": [0, 11]}, {"6 6": [0, 12]}, {"6 6": [1, 0]}, {"6 6": [1, 1]}, {"6 6": [1, 2]}, {"6 6": [1, 3]}, {"6 6": [1, 4]}, {"6 6": [1, 5]}, {"6 6": [1, 6]}, {"6 6": [1, 7]}, {"6 6": [1, 8]}, {"6 6": [1, 9]}, {"6 6": [1, 10]}, {"6 6": [1, 11]}, {"6 6": [1, 12]}, {"6 6": [2, 0]}, {"6 6": [2, 1]}, {"6 6": [2, 2]}, {"6 6": [2, 3]}, {"6 6": [2, 4]}, {"6 6": [2, 5]}, {"6 6": [2, 6]}, {"6 6": [2, 7]}, {"6 6": [2, 8]}, {"6 6": [2, 9]}, {"6 6": [2, 10]}, {"6 6": [2, 11]}, {"6 6": [2, 12]}, {"6 6": [3, 0]}, {"6 6": [3, 1]}, {"6 6": [3, 2]}, {"6 6": [3, 3]}, {"6 6": [3, 4]}, {"6 6": [3, 5]}, {"6 6": [3, 6]}, {"6 6": [3, 7]}, {"6 6": [3, 8]}, {"6 6": [3, 9]}, {"6 6": [3, 10]}, {"6 6": [3, 11]}, {"6 6": [3, 12]}, {"6 6": [4, 0]}, {"6 6": [4, 1]}, {"6 6": [4, 2]}, {"6 6": [4, 3]}, {"6 6": [4, 4]}, {"6 6": [4, 5]}, {"6 6": [4, 6]}, {"6 6": [4, 7]}, {"6 6": [4, 8]}, {"6 6": [4, 9]}, {"6 6": [4, 10]}, {"6 6": [4, 11]}, {"6 6": [4, 12]}, {"6 6": [5, 0]}, {"6 6": [5, 1]}, {"6 6": [5, 2]}, {"6 6": [5, 3]}, {"6 6": [5, 4]}, {"6 6": [5, 5]}, {"6 6": [5, 6]}, {"6 6": [5, 7]}, {"6 6": [5, 8]}, {"6 6": [5, 9]}, {"6 6": [5, 10]}, {"6 6": [5, 11]}, {"6 6": [5, 12]}, {"6 6": [6, 0]}, {"6 6": [6, 1]}, {"6 6": [6, 2]}, {"6 6": [6, 3]}, {"6 6": [6, 4]}, {"6 6": [6, 5]}, {"6 6": [6, 6]}, {"6 6": [6, 7]}, {"6 6": [6, 8]}, {"6 6": [6, 9]}, {"6 6": [6, 10]}, {"6 6": [6, 11]}, {"6 6": [6, 12]}, {"6 6": [7, 0]}, {"6 6": [7, 1]}, {"6 6": [7, 2]}, {"6 6": [7, 3]}, {"6 6": [7, 4]}, {"6 6": [7, 5]}, {"6 6": [7, 6]}, {"6 6": [7, 7]}, {"6 6": [7, 8]}, {"6 6": [7, 9]}, {"6 6": [7, 10]}, {"6 6": [7, 11]}, {"6 6": [7, 12]}, {"6 6": [8, 0]}, {"6 6": [8, 1]}, {"6 6": [8, 2]}, {"6 6": [8, 3]}, {"6 6": [8, 4]}, {"6 6": [8, 5]}, {"6 6": [8, 6]}, {"6 6": [8, 7]}, {"6 6": [8, 8]}, {"6 6": [8, 9]}, {"6 6": [8, 10]}, {"6 6": [8, 11]}, {"6 6": [8, 12]}, {"6 6": [9, 0]}, {"6 6": [9, 1]}, {"6 6": [9, 2]}, {"6 6": [9, 3]}, {"6 6": [9, 4]}, {"6 6": [9, 5]}, {"6 6": [9, 6]}, {"6 6": [9, 7]}, {"6 6": [9, 8]}, {"6 6": [9, 9]}, {"6 6": [9, 10]}, {"6 6": [9, 11]}, {"6 6": [9, 12]}, {"6 6": [10, 0]}, {"6 6": [10, 1]}, {"6 6": [10, 2]}, {"6 6": [10, 3]}, {"6 6": [10, 4]}, {"6 6": [10, 5]}, {"6 6": [10, 6]}, {"6 6": [10, 7]}, {"6 6": [10, 8]}, {"6 6": [10, 9]}, {"6 6": [10, 10]}, {"6 6": [10, 11]}, {"6 6": [10, 12]}, {"6 6": [11, 0]}, {"6 6": [11, 1]}, {"6 6": [11, 2]}, {"6 6": [11, 3]}, {"6 6": [11, 4]}, {"6 6": [11, 5]}, {"6 6": [11, 6]}, {"6 6": [11, 7]}, {"6 6": [11, 8]}, {"6 6": [11, 9]}, {"6 6": [11, 10]}, {"6 6": [11, 11]}, {"6 6": [11, 12]}, {"6 6": [12, 0]}, {"6 6": [12, 1]}, {"6 6": [12, 2]}, {"6 6": [12, 3]}, {"6 6": [12, 4]}, {"6 6": [12, 5]}, {"6 6": [12, 6]}, {"6 6": [12, 7]}, {"6 6": [12, 8]}, {"6 6": [12, 9]}, {"6 6": [12, 10]}, {"6 6": [12, 11]}, {"6 6": [12, 12]}]
|
| 19 |
+
o_component=H
|
| 20 |
+
energy_component=summation
|
| 21 |
+
max_element=-1
|
| 22 |
+
statistics=False
|
| 23 |
+
normalizer=False
|
| 24 |
+
boxcox=False
|
| 25 |
+
|
| 26 |
+
[graph]
|
| 27 |
+
radius=-1.0
|
| 28 |
+
max_num_nbr=0
|
| 29 |
+
create_from_dft=True
|
| 30 |
+
if_lcmp_graph=True
|
| 31 |
+
separate_onsite=False
|
| 32 |
+
new_sp=False
|
| 33 |
+
|
| 34 |
+
[train]
|
| 35 |
+
epochs=5000
|
| 36 |
+
pretrained=
|
| 37 |
+
resume=
|
| 38 |
+
train_ratio=0.6
|
| 39 |
+
val_ratio=0.2
|
| 40 |
+
test_ratio=0.2
|
| 41 |
+
early_stopping_loss=0.0
|
| 42 |
+
early_stopping_loss_epoch=[0.000000, 500]
|
| 43 |
+
revert_then_decay=True
|
| 44 |
+
revert_threshold=30
|
| 45 |
+
revert_decay_epoch=[800, 2000, 3000, 4000]
|
| 46 |
+
revert_decay_gamma=[0.4, 0.5, 0.5, 0.4]
|
| 47 |
+
clip_grad=True
|
| 48 |
+
clip_grad_value=4.2
|
| 49 |
+
switch_sgd=False
|
| 50 |
+
switch_sgd_lr=1e-4
|
| 51 |
+
switch_sgd_epoch=-1
|
| 52 |
+
|
| 53 |
+
[hyperparameter]
|
| 54 |
+
batch_size=1
|
| 55 |
+
dtype=float32
|
| 56 |
+
optimizer=adam
|
| 57 |
+
learning_rate=0.001
|
| 58 |
+
lr_scheduler=
|
| 59 |
+
lr_milestones=[]
|
| 60 |
+
momentum=0.9
|
| 61 |
+
weight_decay=0
|
| 62 |
+
criterion=MaskMSELoss
|
| 63 |
+
retain_edge_fea=True
|
| 64 |
+
lambda_eij=0.0
|
| 65 |
+
lambda_ei=0.1
|
| 66 |
+
lambda_etot=0.0
|
| 67 |
+
|
| 68 |
+
[network]
|
| 69 |
+
atom_fea_len=64
|
| 70 |
+
edge_fea_len=128
|
| 71 |
+
gauss_stop=6.0
|
| 72 |
+
num_l=4
|
| 73 |
+
aggr=add
|
| 74 |
+
distance_expansion=GaussianBasis
|
| 75 |
+
if_exp=True
|
| 76 |
+
if_multiplelinear=False
|
| 77 |
+
if_edge_update=True
|
| 78 |
+
if_lcmp=True
|
| 79 |
+
normalization=LayerNorm
|
| 80 |
+
atom_update_net=PAINN
|
| 81 |
+
trainable_gaussians=False
|
| 82 |
+
type_affine=False
|
| 83 |
+
|
| 84 |
+
=> load best checkpoint (epoch 3217)
|
| 85 |
+
=> Atomic types: [6], spinful: False, the number of atomic types: 1.
|
| 86 |
+
Save processed graph to /home/apolyukhin/scripts/ml/diamond-qe/diamond_epc/displacements/group_8/reconstruction/aohamiltonian/graph.pkl, cost 0.11131572723388672 seconds
|
| 87 |
+
|
| 88 |
0%| | 0/1 [00:00<?, ?it/s]
|
3_epc/displacements/group_8/reconstruction/aohamiltonian/pred_ham_std/src/deeph/__init__.py
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from .data import HData
|
| 2 |
+
from .model import HGNN, ExpBernsteinBasis
|
| 3 |
+
from .utils import print_args, Logger, MaskMSELoss, MaskMAELoss, write_ham_npz, write_ham, write_ham_h5, get_config, \
|
| 4 |
+
get_inference_config, get_preprocess_config
|
| 5 |
+
from .graph import Collater, collate_fn, get_graph, load_orbital_types
|
| 6 |
+
from .kernel import DeepHKernel
|
| 7 |
+
from .preprocess import get_rc, OijLoad, GetEEiEij, abacus_parse, siesta_parse
|
| 8 |
+
from .rotate import get_rh, rotate_back, Rotate, dtype_dict
|
| 9 |
+
|
| 10 |
+
__version__ = "0.2.2"
|
3_epc/displacements/group_8/reconstruction/aohamiltonian/pred_ham_std/src/deeph/data.py
ADDED
|
@@ -0,0 +1,217 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import warnings
|
| 2 |
+
import os
|
| 3 |
+
import time
|
| 4 |
+
import tqdm
|
| 5 |
+
|
| 6 |
+
from pymatgen.core.structure import Structure
|
| 7 |
+
import numpy as np
|
| 8 |
+
import torch
|
| 9 |
+
from torch_geometric.data import InMemoryDataset
|
| 10 |
+
from pathos.multiprocessing import ProcessingPool as Pool
|
| 11 |
+
|
| 12 |
+
from .graph import get_graph
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
class HData(InMemoryDataset):
|
| 16 |
+
def __init__(self, raw_data_dir: str, graph_dir: str, interface: str, target: str,
|
| 17 |
+
dataset_name: str, multiprocessing: int, radius, max_num_nbr,
|
| 18 |
+
num_l, max_element, create_from_DFT, if_lcmp_graph, separate_onsite, new_sp,
|
| 19 |
+
default_dtype_torch, nums: int = None, transform=None, pre_transform=None, pre_filter=None):
|
| 20 |
+
"""
|
| 21 |
+
when interface == 'h5',
|
| 22 |
+
raw_data_dir
|
| 23 |
+
├── 00
|
| 24 |
+
│ ├──rh.h5 / rdm.h5
|
| 25 |
+
│ ├──rc.h5
|
| 26 |
+
│ ├──element.dat
|
| 27 |
+
│ ├──orbital_types.dat
|
| 28 |
+
│ ├──site_positions.dat
|
| 29 |
+
│ ├──lat.dat
|
| 30 |
+
│ └──info.json
|
| 31 |
+
├── 01
|
| 32 |
+
│ ├──rh.h5 / rdm.h5
|
| 33 |
+
│ ├──rc.h5
|
| 34 |
+
│ ├──element.dat
|
| 35 |
+
│ ├──orbital_types.dat
|
| 36 |
+
│ ├──site_positions.dat
|
| 37 |
+
│ ├──lat.dat
|
| 38 |
+
│ └──info.json
|
| 39 |
+
├── 02
|
| 40 |
+
│ ├──rh.h5 / rdm.h5
|
| 41 |
+
│ ├──rc.h5
|
| 42 |
+
│ ├──element.dat
|
| 43 |
+
│ ├──orbital_types.dat
|
| 44 |
+
│ ├──site_positions.dat
|
| 45 |
+
│ ├──lat.dat
|
| 46 |
+
│ └──info.json
|
| 47 |
+
├── ...
|
| 48 |
+
"""
|
| 49 |
+
self.raw_data_dir = raw_data_dir
|
| 50 |
+
assert dataset_name.find('-') == -1, '"-" can not be included in the dataset name'
|
| 51 |
+
if create_from_DFT:
|
| 52 |
+
way_create_graph = 'FromDFT'
|
| 53 |
+
else:
|
| 54 |
+
way_create_graph = f'{radius}r{max_num_nbr}mn'
|
| 55 |
+
if if_lcmp_graph:
|
| 56 |
+
lcmp_str = f'{num_l}l'
|
| 57 |
+
else:
|
| 58 |
+
lcmp_str = 'WithoutLCMP'
|
| 59 |
+
if separate_onsite is True:
|
| 60 |
+
onsite_str = '-SeparateOnsite'
|
| 61 |
+
else:
|
| 62 |
+
onsite_str = ''
|
| 63 |
+
if new_sp:
|
| 64 |
+
new_sp_str = '-NewSP'
|
| 65 |
+
else:
|
| 66 |
+
new_sp_str = ''
|
| 67 |
+
if target == 'hamiltonian':
|
| 68 |
+
title = 'HGraph'
|
| 69 |
+
else:
|
| 70 |
+
raise ValueError('Unknown prediction target: {}'.format(target))
|
| 71 |
+
graph_file_name = f'{title}-{interface}-{dataset_name}-{lcmp_str}-{way_create_graph}{onsite_str}{new_sp_str}.pkl'
|
| 72 |
+
self.data_file = os.path.join(graph_dir, graph_file_name)
|
| 73 |
+
os.makedirs(graph_dir, exist_ok=True)
|
| 74 |
+
self.data, self.slices = None, None
|
| 75 |
+
self.interface = interface
|
| 76 |
+
self.target = target
|
| 77 |
+
self.dataset_name = dataset_name
|
| 78 |
+
self.multiprocessing = multiprocessing
|
| 79 |
+
self.radius = radius
|
| 80 |
+
self.max_num_nbr = max_num_nbr
|
| 81 |
+
self.num_l = num_l
|
| 82 |
+
self.create_from_DFT = create_from_DFT
|
| 83 |
+
self.if_lcmp_graph = if_lcmp_graph
|
| 84 |
+
self.separate_onsite = separate_onsite
|
| 85 |
+
self.new_sp = new_sp
|
| 86 |
+
self.default_dtype_torch = default_dtype_torch
|
| 87 |
+
|
| 88 |
+
self.nums = nums
|
| 89 |
+
self.transform = transform
|
| 90 |
+
self.pre_transform = pre_transform
|
| 91 |
+
self.pre_filter = pre_filter
|
| 92 |
+
self.__indices__ = None
|
| 93 |
+
self.__data_list__ = None
|
| 94 |
+
self._indices = None
|
| 95 |
+
self._data_list = None
|
| 96 |
+
|
| 97 |
+
print(f'Graph data file: {graph_file_name}')
|
| 98 |
+
if os.path.exists(self.data_file):
|
| 99 |
+
print('Use existing graph data file')
|
| 100 |
+
else:
|
| 101 |
+
print('Process new data file......')
|
| 102 |
+
self.process()
|
| 103 |
+
begin = time.time()
|
| 104 |
+
try:
|
| 105 |
+
loaded_data = torch.load(self.data_file)
|
| 106 |
+
except AttributeError:
|
| 107 |
+
raise RuntimeError('Error in loading graph data file, try to delete it and generate the graph file with the current version of PyG')
|
| 108 |
+
if len(loaded_data) == 2:
|
| 109 |
+
warnings.warn('You are using the graph data file with an old version')
|
| 110 |
+
self.data, self.slices = loaded_data
|
| 111 |
+
self.info = {
|
| 112 |
+
"spinful": False,
|
| 113 |
+
"index_to_Z": torch.arange(max_element + 1),
|
| 114 |
+
"Z_to_index": torch.arange(max_element + 1),
|
| 115 |
+
}
|
| 116 |
+
elif len(loaded_data) == 3:
|
| 117 |
+
self.data, self.slices, tmp = loaded_data
|
| 118 |
+
if isinstance(tmp, dict):
|
| 119 |
+
self.info = tmp
|
| 120 |
+
print(f"Atomic types: {self.info['index_to_Z'].tolist()}")
|
| 121 |
+
else:
|
| 122 |
+
warnings.warn('You are using an old version of the graph data file')
|
| 123 |
+
self.info = {
|
| 124 |
+
"spinful": tmp,
|
| 125 |
+
"index_to_Z": torch.arange(max_element + 1),
|
| 126 |
+
"Z_to_index": torch.arange(max_element + 1),
|
| 127 |
+
}
|
| 128 |
+
print(f'Finish loading the processed {len(self)} structures (spinful: {self.info["spinful"]}, '
|
| 129 |
+
f'the number of atomic types: {len(self.info["index_to_Z"])}), cost {time.time() - begin:.0f} seconds')
|
| 130 |
+
|
| 131 |
+
def process_worker(self, folder, **kwargs):
|
| 132 |
+
stru_id = os.path.split(folder)[-1]
|
| 133 |
+
|
| 134 |
+
structure = Structure(np.loadtxt(os.path.join(folder, 'lat.dat')).T,
|
| 135 |
+
np.loadtxt(os.path.join(folder, 'element.dat')),
|
| 136 |
+
np.loadtxt(os.path.join(folder, 'site_positions.dat')).T,
|
| 137 |
+
coords_are_cartesian=True,
|
| 138 |
+
to_unit_cell=False)
|
| 139 |
+
|
| 140 |
+
cart_coords = torch.tensor(structure.cart_coords, dtype=self.default_dtype_torch)
|
| 141 |
+
frac_coords = torch.tensor(structure.frac_coords, dtype=self.default_dtype_torch)
|
| 142 |
+
numbers = torch.tensor(structure.atomic_numbers)
|
| 143 |
+
structure.lattice.matrix.setflags(write=True)
|
| 144 |
+
lattice = torch.tensor(structure.lattice.matrix, dtype=self.default_dtype_torch)
|
| 145 |
+
if self.target == 'E_ij':
|
| 146 |
+
huge_structure = True
|
| 147 |
+
else:
|
| 148 |
+
huge_structure = False
|
| 149 |
+
return get_graph(cart_coords, frac_coords, numbers, stru_id, r=self.radius, max_num_nbr=self.max_num_nbr,
|
| 150 |
+
numerical_tol=1e-8, lattice=lattice, default_dtype_torch=self.default_dtype_torch,
|
| 151 |
+
tb_folder=folder, interface=self.interface, num_l=self.num_l,
|
| 152 |
+
create_from_DFT=self.create_from_DFT, if_lcmp_graph=self.if_lcmp_graph,
|
| 153 |
+
separate_onsite=self.separate_onsite,
|
| 154 |
+
target=self.target, huge_structure=huge_structure, if_new_sp=self.new_sp, **kwargs)
|
| 155 |
+
|
| 156 |
+
def process(self):
|
| 157 |
+
begin = time.time()
|
| 158 |
+
folder_list = []
|
| 159 |
+
for root, dirs, files in os.walk(self.raw_data_dir):
|
| 160 |
+
if (self.interface == 'h5' and 'rc.h5' in files) or (
|
| 161 |
+
self.interface == 'npz' and 'rc.npz' in files):
|
| 162 |
+
folder_list.append(root)
|
| 163 |
+
folder_list = sorted(folder_list)
|
| 164 |
+
folder_list = folder_list[: self.nums]
|
| 165 |
+
if self.dataset_name == 'graphene_450':
|
| 166 |
+
folder_list = folder_list[500:5000:10]
|
| 167 |
+
if self.dataset_name == 'graphene_1500':
|
| 168 |
+
folder_list = folder_list[500:5000:3]
|
| 169 |
+
if self.dataset_name == 'bp_bilayer':
|
| 170 |
+
folder_list = folder_list[:600]
|
| 171 |
+
assert len(folder_list) != 0, "Can not find any structure"
|
| 172 |
+
print('Found %d structures, have cost %d seconds' % (len(folder_list), time.time() - begin))
|
| 173 |
+
|
| 174 |
+
if self.multiprocessing == 0:
|
| 175 |
+
print(f'Use multiprocessing (nodes = num_processors x num_threads = 1 x {torch.get_num_threads()})')
|
| 176 |
+
data_list = [self.process_worker(folder) for folder in tqdm.tqdm(folder_list)]
|
| 177 |
+
else:
|
| 178 |
+
pool_dict = {} if self.multiprocessing < 0 else {'nodes': self.multiprocessing}
|
| 179 |
+
# BS (2023.06.06):
|
| 180 |
+
# The keyword "num_threads" in kernel.py can be used to set the torch threads.
|
| 181 |
+
# The multiprocessing in the "process_worker" is in contradiction with the num_threads utilized in torch.
|
| 182 |
+
# To avoid this conflict, I limit the number of torch threads to one,
|
| 183 |
+
# and recover it when finishing the process_worker.
|
| 184 |
+
torch_num_threads = torch.get_num_threads()
|
| 185 |
+
torch.set_num_threads(1)
|
| 186 |
+
|
| 187 |
+
with Pool(**pool_dict) as pool:
|
| 188 |
+
nodes = pool.nodes
|
| 189 |
+
print(f'Use multiprocessing (nodes = num_processors x num_threads = {nodes} x {torch.get_num_threads()})')
|
| 190 |
+
data_list = list(tqdm.tqdm(pool.imap(self.process_worker, folder_list), total=len(folder_list)))
|
| 191 |
+
torch.set_num_threads(torch_num_threads)
|
| 192 |
+
print('Finish processing %d structures, have cost %d seconds' % (len(data_list), time.time() - begin))
|
| 193 |
+
|
| 194 |
+
if self.pre_filter is not None:
|
| 195 |
+
data_list = [d for d in data_list if self.pre_filter(d)]
|
| 196 |
+
if self.pre_transform is not None:
|
| 197 |
+
data_list = [self.pre_transform(d) for d in data_list]
|
| 198 |
+
|
| 199 |
+
index_to_Z, Z_to_index = self.element_statistics(data_list)
|
| 200 |
+
spinful = data_list[0].spinful
|
| 201 |
+
for d in data_list:
|
| 202 |
+
assert spinful == d.spinful
|
| 203 |
+
|
| 204 |
+
data, slices = self.collate(data_list)
|
| 205 |
+
torch.save((data, slices, dict(spinful=spinful, index_to_Z=index_to_Z, Z_to_index=Z_to_index)), self.data_file)
|
| 206 |
+
print('Finish saving %d structures to %s, have cost %d seconds' % (
|
| 207 |
+
len(data_list), self.data_file, time.time() - begin))
|
| 208 |
+
|
| 209 |
+
def element_statistics(self, data_list):
|
| 210 |
+
index_to_Z, inverse_indices = torch.unique(data_list[0].x, sorted=True, return_inverse=True)
|
| 211 |
+
Z_to_index = torch.full((100,), -1, dtype=torch.int64)
|
| 212 |
+
Z_to_index[index_to_Z] = torch.arange(len(index_to_Z))
|
| 213 |
+
|
| 214 |
+
for data in data_list:
|
| 215 |
+
data.x = Z_to_index[data.x]
|
| 216 |
+
|
| 217 |
+
return index_to_Z, Z_to_index
|
3_epc/displacements/group_8/reconstruction/aohamiltonian/pred_ham_std/src/deeph/default.ini
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[basic]
|
| 2 |
+
graph_dir = /your/own/path
|
| 3 |
+
save_dir = /your/own/path
|
| 4 |
+
raw_dir = /your/own/path
|
| 5 |
+
dataset_name = your_own_name
|
| 6 |
+
only_get_graph = False
|
| 7 |
+
;choices = ['h5', 'npz']
|
| 8 |
+
interface = h5
|
| 9 |
+
target = hamiltonian
|
| 10 |
+
disable_cuda = False
|
| 11 |
+
device = cuda:0
|
| 12 |
+
;-1 for cpu_count(logical=False) // torch.cuda.device_count()
|
| 13 |
+
num_threads = -1
|
| 14 |
+
save_to_time_folder = True
|
| 15 |
+
save_csv = False
|
| 16 |
+
tb_writer = True
|
| 17 |
+
seed = 42
|
| 18 |
+
multiprocessing = 0
|
| 19 |
+
orbital = [{"6 6": [0, 0]}, {"6 6": [0, 1]}, {"6 6": [0, 2]}, {"6 6": [0, 3]}, {"6 6": [0, 4]}, {"6 6": [0, 5]}, {"6 6": [0, 6]}, {"6 6": [0, 7]}, {"6 6": [0, 8]}, {"6 6": [0, 9]}, {"6 6": [0, 10]}, {"6 6": [0, 11]}, {"6 6": [0, 12]}, {"6 6": [1, 0]}, {"6 6": [1, 1]}, {"6 6": [1, 2]}, {"6 6": [1, 3]}, {"6 6": [1, 4]}, {"6 6": [1, 5]}, {"6 6": [1, 6]}, {"6 6": [1, 7]}, {"6 6": [1, 8]}, {"6 6": [1, 9]}, {"6 6": [1, 10]}, {"6 6": [1, 11]}, {"6 6": [1, 12]}, {"6 6": [2, 0]}, {"6 6": [2, 1]}, {"6 6": [2, 2]}, {"6 6": [2, 3]}, {"6 6": [2, 4]}, {"6 6": [2, 5]}, {"6 6": [2, 6]}, {"6 6": [2, 7]}, {"6 6": [2, 8]}, {"6 6": [2, 9]}, {"6 6": [2, 10]}, {"6 6": [2, 11]}, {"6 6": [2, 12]}, {"6 6": [3, 0]}, {"6 6": [3, 1]}, {"6 6": [3, 2]}, {"6 6": [3, 3]}, {"6 6": [3, 4]}, {"6 6": [3, 5]}, {"6 6": [3, 6]}, {"6 6": [3, 7]}, {"6 6": [3, 8]}, {"6 6": [3, 9]}, {"6 6": [3, 10]}, {"6 6": [3, 11]}, {"6 6": [3, 12]}, {"6 6": [4, 0]}, {"6 6": [4, 1]}, {"6 6": [4, 2]}, {"6 6": [4, 3]}, {"6 6": [4, 4]}, {"6 6": [4, 5]}, {"6 6": [4, 6]}, {"6 6": [4, 7]}, {"6 6": [4, 8]}, {"6 6": [4, 9]}, {"6 6": [4, 10]}, {"6 6": [4, 11]}, {"6 6": [4, 12]}, {"6 6": [5, 0]}, {"6 6": [5, 1]}, {"6 6": [5, 2]}, {"6 6": [5, 3]}, {"6 6": [5, 4]}, {"6 6": [5, 5]}, {"6 6": [5, 6]}, {"6 6": [5, 7]}, {"6 6": [5, 8]}, {"6 6": [5, 9]}, {"6 6": [5, 10]}, {"6 6": [5, 11]}, {"6 6": [5, 12]}, {"6 6": [6, 0]}, {"6 6": [6, 1]}, {"6 6": [6, 2]}, {"6 6": [6, 3]}, {"6 6": [6, 4]}, {"6 6": [6, 5]}, {"6 6": [6, 6]}, {"6 6": [6, 7]}, {"6 6": [6, 8]}, {"6 6": [6, 9]}, {"6 6": [6, 10]}, {"6 6": [6, 11]}, {"6 6": [6, 12]}, {"6 6": [7, 0]}, {"6 6": [7, 1]}, {"6 6": [7, 2]}, {"6 6": [7, 3]}, {"6 6": [7, 4]}, {"6 6": [7, 5]}, {"6 6": [7, 6]}, {"6 6": [7, 7]}, {"6 6": [7, 8]}, {"6 6": [7, 9]}, {"6 6": [7, 10]}, {"6 6": [7, 11]}, {"6 6": [7, 12]}, {"6 6": [8, 0]}, {"6 6": [8, 1]}, {"6 6": [8, 2]}, {"6 6": [8, 3]}, {"6 6": [8, 4]}, {"6 6": [8, 5]}, {"6 6": [8, 6]}, {"6 6": [8, 7]}, {"6 6": [8, 8]}, {"6 6": [8, 9]}, {"6 6": [8, 10]}, {"6 6": [8, 11]}, {"6 6": [8, 12]}, {"6 6": [9, 0]}, {"6 6": [9, 1]}, {"6 6": [9, 2]}, {"6 6": [9, 3]}, {"6 6": [9, 4]}, {"6 6": [9, 5]}, {"6 6": [9, 6]}, {"6 6": [9, 7]}, {"6 6": [9, 8]}, {"6 6": [9, 9]}, {"6 6": [9, 10]}, {"6 6": [9, 11]}, {"6 6": [9, 12]}, {"6 6": [10, 0]}, {"6 6": [10, 1]}, {"6 6": [10, 2]}, {"6 6": [10, 3]}, {"6 6": [10, 4]}, {"6 6": [10, 5]}, {"6 6": [10, 6]}, {"6 6": [10, 7]}, {"6 6": [10, 8]}, {"6 6": [10, 9]}, {"6 6": [10, 10]}, {"6 6": [10, 11]}, {"6 6": [10, 12]}, {"6 6": [11, 0]}, {"6 6": [11, 1]}, {"6 6": [11, 2]}, {"6 6": [11, 3]}, {"6 6": [11, 4]}, {"6 6": [11, 5]}, {"6 6": [11, 6]}, {"6 6": [11, 7]}, {"6 6": [11, 8]}, {"6 6": [11, 9]}, {"6 6": [11, 10]}, {"6 6": [11, 11]}, {"6 6": [11, 12]}, {"6 6": [12, 0]}, {"6 6": [12, 1]}, {"6 6": [12, 2]}, {"6 6": [12, 3]}, {"6 6": [12, 4]}, {"6 6": [12, 5]}, {"6 6": [12, 6]}, {"6 6": [12, 7]}, {"6 6": [12, 8]}, {"6 6": [12, 9]}, {"6 6": [12, 10]}, {"6 6": [12, 11]}, {"6 6": [12, 12]}]
|
| 20 |
+
O_component = H
|
| 21 |
+
energy_component = summation
|
| 22 |
+
max_element = -1
|
| 23 |
+
statistics = False
|
| 24 |
+
normalizer = False
|
| 25 |
+
boxcox = False
|
| 26 |
+
|
| 27 |
+
[graph]
|
| 28 |
+
radius = -1.0
|
| 29 |
+
max_num_nbr = 0
|
| 30 |
+
create_from_DFT = True
|
| 31 |
+
if_lcmp_graph = True
|
| 32 |
+
separate_onsite = False
|
| 33 |
+
new_sp = False
|
| 34 |
+
|
| 35 |
+
[train]
|
| 36 |
+
epochs = 4000
|
| 37 |
+
pretrained =
|
| 38 |
+
resume =
|
| 39 |
+
train_ratio = 0.6
|
| 40 |
+
val_ratio = 0.2
|
| 41 |
+
test_ratio = 0.2
|
| 42 |
+
early_stopping_loss = 0.0
|
| 43 |
+
early_stopping_loss_epoch = [0.000000, 500]
|
| 44 |
+
revert_then_decay = True
|
| 45 |
+
revert_threshold = 30
|
| 46 |
+
revert_decay_epoch = [500, 2000, 3000]
|
| 47 |
+
revert_decay_gamma = [0.4, 0.5, 0.5]
|
| 48 |
+
clip_grad = True
|
| 49 |
+
clip_grad_value = 4.2
|
| 50 |
+
switch_sgd = False
|
| 51 |
+
switch_sgd_lr = 1e-4
|
| 52 |
+
switch_sgd_epoch = -1
|
| 53 |
+
|
| 54 |
+
[hyperparameter]
|
| 55 |
+
batch_size = 3
|
| 56 |
+
dtype = float32
|
| 57 |
+
;choices = ['sgd', 'sgdm', 'adam', 'lbfgs']
|
| 58 |
+
optimizer = adam
|
| 59 |
+
;initial learning rate
|
| 60 |
+
learning_rate = 0.001
|
| 61 |
+
;choices = ['', 'MultiStepLR', 'ReduceLROnPlateau', 'CyclicLR']
|
| 62 |
+
lr_scheduler =
|
| 63 |
+
lr_milestones = []
|
| 64 |
+
momentum = 0.9
|
| 65 |
+
weight_decay = 0
|
| 66 |
+
criterion = MaskMSELoss
|
| 67 |
+
retain_edge_fea = True
|
| 68 |
+
lambda_Eij = 0.0
|
| 69 |
+
lambda_Ei = 0.1
|
| 70 |
+
lambda_Etot = 0.0
|
| 71 |
+
|
| 72 |
+
[network]
|
| 73 |
+
atom_fea_len = 64
|
| 74 |
+
edge_fea_len = 128
|
| 75 |
+
gauss_stop = 6
|
| 76 |
+
;The number of angular quantum numbers that spherical harmonic functions have
|
| 77 |
+
num_l = 5
|
| 78 |
+
aggr = add
|
| 79 |
+
distance_expansion = GaussianBasis
|
| 80 |
+
if_exp = True
|
| 81 |
+
if_MultipleLinear = False
|
| 82 |
+
if_edge_update = True
|
| 83 |
+
if_lcmp = True
|
| 84 |
+
normalization = LayerNorm
|
| 85 |
+
;choices = ['CGConv', 'GAT', 'PAINN']
|
| 86 |
+
atom_update_net = CGConv
|
| 87 |
+
trainable_gaussians = False
|
| 88 |
+
type_affine = False
|
3_epc/displacements/group_8/reconstruction/aohamiltonian/pred_ham_std/src/deeph/from_HermNet/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
from .rmnet import RBF, cosine_cutoff, ShiftedSoftplus, _eps
|
3_epc/displacements/group_8/reconstruction/aohamiltonian/pred_ham_std/src/deeph/from_HermNet/__pycache__/__init__.cpython-312.pyc
ADDED
|
Binary file (263 Bytes). View file
|
|
|
3_epc/displacements/group_8/reconstruction/aohamiltonian/pred_ham_std/src/deeph/from_HermNet/__pycache__/rmnet.cpython-312.pyc
ADDED
|
Binary file (4.67 kB). View file
|
|
|
3_epc/displacements/group_8/reconstruction/aohamiltonian/pred_ham_std/src/deeph/from_HermNet/license.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
The code in this folder was obtained from "https://github.com/sakuraiiiii/HermNet"
|
3_epc/displacements/group_8/reconstruction/aohamiltonian/pred_ham_std/src/deeph/from_HermNet/rmnet.py
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import math
|
| 2 |
+
|
| 3 |
+
import torch
|
| 4 |
+
from torch import nn, Tensor
|
| 5 |
+
import numpy as np
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
_eps = 1e-3
|
| 9 |
+
|
| 10 |
+
r"""Tricks: Introducing the parameter `_eps` is to avoid NaN.
|
| 11 |
+
In HVNet and HTNet, a subgraph will be extracted to calculate angles.
|
| 12 |
+
And with all the nodes still be included in the subgraph,
|
| 13 |
+
each hidden state in such a subgraph will contain 0 value.
|
| 14 |
+
In `painn`, the calculation w.r.t $r / \parallel r \parallel$ will be taken.
|
| 15 |
+
If just alternate $r / \parallel r \parallel$ with $r / (\parallel r \parallel + _eps)$,
|
| 16 |
+
NaN will still occur in during the training.
|
| 17 |
+
Considering the following example,
|
| 18 |
+
$$
|
| 19 |
+
(\frac{x}{r+_eps})^\prime = \frac{r+b-\frac{x^2}{r}}{(r+b)^2}
|
| 20 |
+
$$
|
| 21 |
+
where $r = \sqrt{x^2+y^2+z^2}$. It is obvious that NaN will occur.
|
| 22 |
+
Thus the solution is change the norm $r$ as $r^\prime = \sqrt(x^2+y^2+z^2+_eps)$.
|
| 23 |
+
Since $r$ is rotational invariant, $r^2$ is rotational invariant.
|
| 24 |
+
Obviously, $\sqrt(r^2 + _eps)$ is rotational invariant.
|
| 25 |
+
"""
|
| 26 |
+
class RBF(nn.Module):
|
| 27 |
+
r"""Radial basis function.
|
| 28 |
+
A modified version of feature engineering in `DimeNet`,
|
| 29 |
+
which is used in `PAINN`.
|
| 30 |
+
|
| 31 |
+
Parameters
|
| 32 |
+
----------
|
| 33 |
+
rc : float
|
| 34 |
+
Cutoff radius
|
| 35 |
+
l : int
|
| 36 |
+
Parameter in feature engineering in DimeNet
|
| 37 |
+
"""
|
| 38 |
+
def __init__(self, rc: float, l: int):
|
| 39 |
+
super(RBF, self).__init__()
|
| 40 |
+
self.rc = rc
|
| 41 |
+
self.l = l
|
| 42 |
+
|
| 43 |
+
def forward(self, x: Tensor):
|
| 44 |
+
ls = torch.arange(1, self.l + 1).float().to(x.device)
|
| 45 |
+
norm = torch.sqrt((x ** 2).sum(dim=-1) + _eps).unsqueeze(-1)
|
| 46 |
+
return torch.sin(math.pi / self.rc * norm@ls.unsqueeze(0)) / norm
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
class cosine_cutoff(nn.Module):
|
| 50 |
+
r"""Cutoff function in https://aip.scitation.org/doi/pdf/10.1063/1.3553717.
|
| 51 |
+
|
| 52 |
+
Parameters
|
| 53 |
+
----------
|
| 54 |
+
rc : float
|
| 55 |
+
Cutoff radius
|
| 56 |
+
"""
|
| 57 |
+
def __init__(self, rc: float):
|
| 58 |
+
super(cosine_cutoff, self).__init__()
|
| 59 |
+
self.rc = rc
|
| 60 |
+
|
| 61 |
+
def forward(self, x: Tensor):
|
| 62 |
+
norm = torch.norm(x, dim=-1, keepdim=True) + _eps
|
| 63 |
+
return 0.5 * (torch.cos(math.pi * norm / self.rc) + 1)
|
| 64 |
+
|
| 65 |
+
class ShiftedSoftplus(nn.Module):
|
| 66 |
+
r"""
|
| 67 |
+
|
| 68 |
+
Description
|
| 69 |
+
-----------
|
| 70 |
+
Applies the element-wise function:
|
| 71 |
+
|
| 72 |
+
.. math::
|
| 73 |
+
\text{SSP}(x) = \frac{1}{\beta} * \log(1 + \exp(\beta * x)) - \log(\text{shift})
|
| 74 |
+
|
| 75 |
+
Attributes
|
| 76 |
+
----------
|
| 77 |
+
beta : int
|
| 78 |
+
:math:`\beta` value for the mathematical formulation. Default to 1.
|
| 79 |
+
shift : int
|
| 80 |
+
:math:`\text{shift}` value for the mathematical formulation. Default to 2.
|
| 81 |
+
"""
|
| 82 |
+
def __init__(self, beta=1, shift=2, threshold=20):
|
| 83 |
+
super(ShiftedSoftplus, self).__init__()
|
| 84 |
+
|
| 85 |
+
self.shift = shift
|
| 86 |
+
self.softplus = nn.Softplus(beta=beta, threshold=threshold)
|
| 87 |
+
|
| 88 |
+
def forward(self, inputs):
|
| 89 |
+
"""
|
| 90 |
+
|
| 91 |
+
Description
|
| 92 |
+
-----------
|
| 93 |
+
Applies the activation function.
|
| 94 |
+
|
| 95 |
+
Parameters
|
| 96 |
+
----------
|
| 97 |
+
inputs : float32 tensor of shape (N, *)
|
| 98 |
+
* denotes any number of additional dimensions.
|
| 99 |
+
|
| 100 |
+
Returns
|
| 101 |
+
-------
|
| 102 |
+
float32 tensor of shape (N, *)
|
| 103 |
+
Result of applying the activation function to the input.
|
| 104 |
+
"""
|
| 105 |
+
return self.softplus(inputs) - np.log(float(self.shift))
|
3_epc/displacements/group_8/reconstruction/aohamiltonian/pred_ham_std/src/deeph/from_PyG_future/__init__.py
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from .graph_norm import GraphNorm
|
| 2 |
+
from .diff_group_norm import DiffGroupNorm
|
3_epc/displacements/group_8/reconstruction/aohamiltonian/pred_ham_std/src/deeph/from_PyG_future/__pycache__/__init__.cpython-312.pyc
ADDED
|
Binary file (263 Bytes). View file
|
|
|
3_epc/displacements/group_8/reconstruction/aohamiltonian/pred_ham_std/src/deeph/from_PyG_future/__pycache__/diff_group_norm.cpython-312.pyc
ADDED
|
Binary file (6.43 kB). View file
|
|
|
3_epc/displacements/group_8/reconstruction/aohamiltonian/pred_ham_std/src/deeph/from_PyG_future/__pycache__/graph_norm.cpython-312.pyc
ADDED
|
Binary file (3.76 kB). View file
|
|
|
3_epc/displacements/group_8/reconstruction/aohamiltonian/pred_ham_std/src/deeph/from_PyG_future/diff_group_norm.py
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from torch import Tensor
|
| 3 |
+
from torch.nn import Linear, BatchNorm1d
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
class DiffGroupNorm(torch.nn.Module):
|
| 7 |
+
r"""The differentiable group normalization layer from the `"Towards Deeper
|
| 8 |
+
Graph Neural Networks with Differentiable Group Normalization"
|
| 9 |
+
<https://arxiv.org/abs/2006.06972>`_ paper, which normalizes node features
|
| 10 |
+
group-wise via a learnable soft cluster assignment
|
| 11 |
+
|
| 12 |
+
.. math::
|
| 13 |
+
|
| 14 |
+
\mathbf{S} = \text{softmax} (\mathbf{X} \mathbf{W})
|
| 15 |
+
|
| 16 |
+
where :math:`\mathbf{W} \in \mathbb{R}^{F \times G}` denotes a trainable
|
| 17 |
+
weight matrix mapping each node into one of :math:`G` clusters.
|
| 18 |
+
Normalization is then performed group-wise via:
|
| 19 |
+
|
| 20 |
+
.. math::
|
| 21 |
+
|
| 22 |
+
\mathbf{X}^{\prime} = \mathbf{X} + \lambda \sum_{i = 1}^G
|
| 23 |
+
\text{BatchNorm}(\mathbf{S}[:, i] \odot \mathbf{X})
|
| 24 |
+
|
| 25 |
+
Args:
|
| 26 |
+
in_channels (int): Size of each input sample :math:`F`.
|
| 27 |
+
groups (int): The number of groups :math:`G`.
|
| 28 |
+
lamda (float, optional): The balancing factor :math:`\lambda` between
|
| 29 |
+
input embeddings and normalized embeddings. (default: :obj:`0.01`)
|
| 30 |
+
eps (float, optional): A value added to the denominator for numerical
|
| 31 |
+
stability. (default: :obj:`1e-5`)
|
| 32 |
+
momentum (float, optional): The value used for the running mean and
|
| 33 |
+
running variance computation. (default: :obj:`0.1`)
|
| 34 |
+
affine (bool, optional): If set to :obj:`True`, this module has
|
| 35 |
+
learnable affine parameters :math:`\gamma` and :math:`\beta`.
|
| 36 |
+
(default: :obj:`True`)
|
| 37 |
+
track_running_stats (bool, optional): If set to :obj:`True`, this
|
| 38 |
+
module tracks the running mean and variance, and when set to
|
| 39 |
+
:obj:`False`, this module does not track such statistics and always
|
| 40 |
+
uses batch statistics in both training and eval modes.
|
| 41 |
+
(default: :obj:`True`)
|
| 42 |
+
"""
|
| 43 |
+
def __init__(self, in_channels, groups, lamda=0.01, eps=1e-5, momentum=0.1,
|
| 44 |
+
affine=True, track_running_stats=True):
|
| 45 |
+
super(DiffGroupNorm, self).__init__()
|
| 46 |
+
|
| 47 |
+
self.in_channels = in_channels
|
| 48 |
+
self.groups = groups
|
| 49 |
+
self.lamda = lamda
|
| 50 |
+
|
| 51 |
+
self.lin = Linear(in_channels, groups, bias=False)
|
| 52 |
+
self.norm = BatchNorm1d(groups * in_channels, eps, momentum, affine,
|
| 53 |
+
track_running_stats)
|
| 54 |
+
|
| 55 |
+
self.reset_parameters()
|
| 56 |
+
|
| 57 |
+
def reset_parameters(self):
|
| 58 |
+
self.lin.reset_parameters()
|
| 59 |
+
self.norm.reset_parameters()
|
| 60 |
+
|
| 61 |
+
def forward(self, x: Tensor) -> Tensor:
|
| 62 |
+
""""""
|
| 63 |
+
F, G = self.in_channels, self.groups
|
| 64 |
+
|
| 65 |
+
s = self.lin(x).softmax(dim=-1) # [N, G]
|
| 66 |
+
out = s.unsqueeze(-1) * x.unsqueeze(-2) # [N, G, F]
|
| 67 |
+
out = self.norm(out.view(-1, G * F)).view(-1, G, F).sum(-2) # [N, F]
|
| 68 |
+
|
| 69 |
+
return x + self.lamda * out
|
| 70 |
+
|
| 71 |
+
@staticmethod
|
| 72 |
+
def group_distance_ratio(x: Tensor, y: Tensor, eps: float = 1e-5) -> float:
|
| 73 |
+
r"""Measures the ratio of inter-group distance over intra-group
|
| 74 |
+
distance
|
| 75 |
+
|
| 76 |
+
.. math::
|
| 77 |
+
R_{\text{Group}} = \frac{\frac{1}{(C-1)^2} \sum_{i!=j}
|
| 78 |
+
\frac{1}{|\mathbf{X}_i||\mathbf{X}_j|} \sum_{\mathbf{x}_{iv}
|
| 79 |
+
\in \mathbf{X}_i } \sum_{\mathbf{x}_{jv^{\prime}} \in \mathbf{X}_j}
|
| 80 |
+
{\| \mathbf{x}_{iv} - \mathbf{x}_{jv^{\prime}} \|}_2 }{
|
| 81 |
+
\frac{1}{C} \sum_{i} \frac{1}{{|\mathbf{X}_i|}^2}
|
| 82 |
+
\sum_{\mathbf{x}_{iv}, \mathbf{x}_{iv^{\prime}} \in \mathbf{X}_i }
|
| 83 |
+
{\| \mathbf{x}_{iv} - \mathbf{x}_{iv^{\prime}} \|}_2 }
|
| 84 |
+
|
| 85 |
+
where :math:`\mathbf{X}_i` denotes the set of all nodes that belong to
|
| 86 |
+
class :math:`i`, and :math:`C` denotes the total number of classes in
|
| 87 |
+
:obj:`y`.
|
| 88 |
+
"""
|
| 89 |
+
num_classes = int(y.max()) + 1
|
| 90 |
+
|
| 91 |
+
numerator = 0.
|
| 92 |
+
for i in range(num_classes):
|
| 93 |
+
mask = y == i
|
| 94 |
+
dist = torch.cdist(x[mask].unsqueeze(0), x[~mask].unsqueeze(0))
|
| 95 |
+
numerator += (1 / dist.numel()) * float(dist.sum())
|
| 96 |
+
numerator *= 1 / (num_classes - 1)**2
|
| 97 |
+
|
| 98 |
+
denominator = 0.
|
| 99 |
+
for i in range(num_classes):
|
| 100 |
+
mask = y == i
|
| 101 |
+
dist = torch.cdist(x[mask].unsqueeze(0), x[mask].unsqueeze(0))
|
| 102 |
+
denominator += (1 / dist.numel()) * float(dist.sum())
|
| 103 |
+
denominator *= 1 / num_classes
|
| 104 |
+
|
| 105 |
+
return numerator / (denominator + eps)
|
| 106 |
+
|
| 107 |
+
def __repr__(self):
|
| 108 |
+
return '{}({}, groups={})'.format(self.__class__.__name__,
|
| 109 |
+
self.in_channels, self.groups)
|
3_epc/displacements/group_8/reconstruction/aohamiltonian/pred_ham_std/src/deeph/from_PyG_future/graph_norm.py
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Optional
|
| 2 |
+
|
| 3 |
+
import torch
|
| 4 |
+
from torch import Tensor
|
| 5 |
+
from torch_scatter import scatter_mean
|
| 6 |
+
|
| 7 |
+
from torch_geometric.nn.inits import zeros, ones
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
class GraphNorm(torch.nn.Module):
|
| 11 |
+
r"""Applies graph normalization over individual graphs as described in the
|
| 12 |
+
`"GraphNorm: A Principled Approach to Accelerating Graph Neural Network
|
| 13 |
+
Training" <https://arxiv.org/abs/2009.03294>`_ paper
|
| 14 |
+
|
| 15 |
+
.. math::
|
| 16 |
+
\mathbf{x}^{\prime}_i = \frac{\mathbf{x} - \alpha \odot
|
| 17 |
+
\textrm{E}[\mathbf{x}]}
|
| 18 |
+
{\sqrt{\textrm{Var}[\mathbf{x} - \alpha \odot \textrm{E}[\mathbf{x}]]
|
| 19 |
+
+ \epsilon}} \odot \gamma + \beta
|
| 20 |
+
|
| 21 |
+
where :math:`\alpha` denotes parameters that learn how much information
|
| 22 |
+
to keep in the mean.
|
| 23 |
+
|
| 24 |
+
Args:
|
| 25 |
+
in_channels (int): Size of each input sample.
|
| 26 |
+
eps (float, optional): A value added to the denominator for numerical
|
| 27 |
+
stability. (default: :obj:`1e-5`)
|
| 28 |
+
"""
|
| 29 |
+
def __init__(self, in_channels: int, eps: float = 1e-5):
|
| 30 |
+
super(GraphNorm, self).__init__()
|
| 31 |
+
|
| 32 |
+
self.in_channels = in_channels
|
| 33 |
+
self.eps = eps
|
| 34 |
+
|
| 35 |
+
self.weight = torch.nn.Parameter(torch.Tensor(in_channels))
|
| 36 |
+
self.bias = torch.nn.Parameter(torch.Tensor(in_channels))
|
| 37 |
+
self.mean_scale = torch.nn.Parameter(torch.Tensor(in_channels))
|
| 38 |
+
|
| 39 |
+
self.reset_parameters()
|
| 40 |
+
|
| 41 |
+
def reset_parameters(self):
|
| 42 |
+
ones(self.weight)
|
| 43 |
+
zeros(self.bias)
|
| 44 |
+
ones(self.mean_scale)
|
| 45 |
+
|
| 46 |
+
def forward(self, x: Tensor, batch: Optional[Tensor] = None) -> Tensor:
|
| 47 |
+
""""""
|
| 48 |
+
if batch is None:
|
| 49 |
+
batch = x.new_zeros(x.size(0), dtype=torch.long)
|
| 50 |
+
|
| 51 |
+
batch_size = int(batch.max()) + 1
|
| 52 |
+
|
| 53 |
+
mean = scatter_mean(x, batch, dim=0, dim_size=batch_size)[batch]
|
| 54 |
+
out = x - mean * self.mean_scale
|
| 55 |
+
var = scatter_mean(out.pow(2), batch, dim=0, dim_size=batch_size)
|
| 56 |
+
std = (var + self.eps).sqrt()[batch]
|
| 57 |
+
return self.weight * out / std + self.bias
|
| 58 |
+
|
| 59 |
+
def __repr__(self):
|
| 60 |
+
return f'{self.__class__.__name__}({self.in_channels})'
|
3_epc/displacements/group_8/reconstruction/aohamiltonian/pred_ham_std/src/deeph/from_PyG_future/license.txt
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
The code in this folder was obtained from "https://github.com/rusty1s/pytorch_geometric", which has the following license:
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
Copyright (c) 2020 Matthias Fey <matthias.fey@tu-dortmund.de>
|
| 5 |
+
|
| 6 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 7 |
+
of this software and associated documentation files (the "Software"), to deal
|
| 8 |
+
in the Software without restriction, including without limitation the rights
|
| 9 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 10 |
+
copies of the Software, and to permit persons to whom the Software is
|
| 11 |
+
furnished to do so, subject to the following conditions:
|
| 12 |
+
|
| 13 |
+
The above copyright notice and this permission notice shall be included in
|
| 14 |
+
all copies or substantial portions of the Software.
|
| 15 |
+
|
| 16 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 17 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 18 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 19 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 20 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 21 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
| 22 |
+
THE SOFTWARE.
|
3_epc/displacements/group_8/reconstruction/aohamiltonian/pred_ham_std/src/deeph/from_pymatgen/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
from .lattice import find_neighbors, _one_to_three, _compute_cube_index, _three_to_one
|
3_epc/displacements/group_8/reconstruction/aohamiltonian/pred_ham_std/src/deeph/from_pymatgen/__pycache__/__init__.cpython-312.pyc
ADDED
|
Binary file (290 Bytes). View file
|
|
|
3_epc/displacements/group_8/reconstruction/aohamiltonian/pred_ham_std/src/deeph/from_pymatgen/__pycache__/lattice.cpython-312.pyc
ADDED
|
Binary file (3.65 kB). View file
|
|
|
3_epc/displacements/group_8/reconstruction/aohamiltonian/pred_ham_std/src/deeph/from_pymatgen/lattice.py
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import itertools
|
| 2 |
+
import numpy as np
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
# The following internal methods are used in the get_points_in_sphere method.
|
| 6 |
+
def _compute_cube_index(coords: np.ndarray, global_min: float, radius: float
|
| 7 |
+
) -> np.ndarray:
|
| 8 |
+
"""
|
| 9 |
+
Compute the cube index from coordinates
|
| 10 |
+
Args:
|
| 11 |
+
coords: (nx3 array) atom coordinates
|
| 12 |
+
global_min: (float) lower boundary of coordinates
|
| 13 |
+
radius: (float) cutoff radius
|
| 14 |
+
|
| 15 |
+
Returns: (nx3 array) int indices
|
| 16 |
+
|
| 17 |
+
"""
|
| 18 |
+
return np.array(np.floor((coords - global_min) / radius), dtype=int)
|
| 19 |
+
|
| 20 |
+
def _three_to_one(label3d: np.ndarray, ny: int, nz: int) -> np.ndarray:
|
| 21 |
+
"""
|
| 22 |
+
The reverse of _one_to_three
|
| 23 |
+
"""
|
| 24 |
+
return np.array(label3d[:, 0] * ny * nz +
|
| 25 |
+
label3d[:, 1] * nz + label3d[:, 2]).reshape((-1, 1))
|
| 26 |
+
|
| 27 |
+
def _one_to_three(label1d: np.ndarray, ny: int, nz: int) -> np.ndarray:
|
| 28 |
+
"""
|
| 29 |
+
Convert a 1D index array to 3D index array
|
| 30 |
+
|
| 31 |
+
Args:
|
| 32 |
+
label1d: (array) 1D index array
|
| 33 |
+
ny: (int) number of cells in y direction
|
| 34 |
+
nz: (int) number of cells in z direction
|
| 35 |
+
|
| 36 |
+
Returns: (nx3) int array of index
|
| 37 |
+
|
| 38 |
+
"""
|
| 39 |
+
last = np.mod(label1d, nz)
|
| 40 |
+
second = np.mod((label1d - last) / nz, ny)
|
| 41 |
+
first = (label1d - last - second * nz) / (ny * nz)
|
| 42 |
+
return np.concatenate([first, second, last], axis=1)
|
| 43 |
+
|
| 44 |
+
def find_neighbors(label: np.ndarray, nx: int, ny: int, nz: int):
|
| 45 |
+
"""
|
| 46 |
+
Given a cube index, find the neighbor cube indices
|
| 47 |
+
|
| 48 |
+
Args:
|
| 49 |
+
label: (array) (n,) or (n x 3) indice array
|
| 50 |
+
nx: (int) number of cells in y direction
|
| 51 |
+
ny: (int) number of cells in y direction
|
| 52 |
+
nz: (int) number of cells in z direction
|
| 53 |
+
|
| 54 |
+
Returns: neighbor cell indices
|
| 55 |
+
|
| 56 |
+
"""
|
| 57 |
+
|
| 58 |
+
array = [[-1, 0, 1]] * 3
|
| 59 |
+
neighbor_vectors = np.array(list(itertools.product(*array)),
|
| 60 |
+
dtype=int)
|
| 61 |
+
if np.shape(label)[1] == 1:
|
| 62 |
+
label3d = _one_to_three(label, ny, nz)
|
| 63 |
+
else:
|
| 64 |
+
label3d = label
|
| 65 |
+
all_labels = label3d[:, None, :] - neighbor_vectors[None, :, :]
|
| 66 |
+
filtered_labels = []
|
| 67 |
+
# filter out out-of-bound labels i.e., label < 0
|
| 68 |
+
for labels in all_labels:
|
| 69 |
+
ind = (labels[:, 0] < nx) * (labels[:, 1] < ny) * (labels[:, 2] < nz) * np.all(labels > -1e-5, axis=1)
|
| 70 |
+
filtered_labels.append(labels[ind])
|
| 71 |
+
return filtered_labels
|
3_epc/displacements/group_8/reconstruction/aohamiltonian/pred_ham_std/src/deeph/from_pymatgen/license.txt
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
The code in this folder was obtained from "https://github.com/materialsproject/pymatgen", which has the following license:
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
The MIT License (MIT)
|
| 5 |
+
Copyright (c) 2011-2012 MIT & The Regents of the University of California, through Lawrence Berkeley National Laboratory
|
| 6 |
+
|
| 7 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
| 8 |
+
this software and associated documentation files (the "Software"), to deal in
|
| 9 |
+
the Software without restriction, including without limitation the rights to
|
| 10 |
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
| 11 |
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
| 12 |
+
subject to the following conditions:
|
| 13 |
+
|
| 14 |
+
The above copyright notice and this permission notice shall be included in all
|
| 15 |
+
copies or substantial portions of the Software.
|
| 16 |
+
|
| 17 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 18 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
| 19 |
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
| 20 |
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
| 21 |
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
| 22 |
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
3_epc/displacements/group_8/reconstruction/aohamiltonian/pred_ham_std/src/deeph/from_schnetpack/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
from .acsf import GaussianBasis
|
3_epc/displacements/group_8/reconstruction/aohamiltonian/pred_ham_std/src/deeph/from_schnetpack/__pycache__/__init__.cpython-312.pyc
ADDED
|
Binary file (207 Bytes). View file
|
|
|
3_epc/displacements/group_8/reconstruction/aohamiltonian/pred_ham_std/src/deeph/from_schnetpack/__pycache__/acsf.cpython-312.pyc
ADDED
|
Binary file (2.45 kB). View file
|
|
|
3_epc/displacements/group_8/reconstruction/aohamiltonian/pred_ham_std/src/deeph/from_schnetpack/acsf.py
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from torch import nn
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
def gaussian_smearing(distances, offset, widths, centered=False):
|
| 6 |
+
if not centered:
|
| 7 |
+
# compute width of Gaussian functions (using an overlap of 1 STDDEV)
|
| 8 |
+
coeff = -0.5 / torch.pow(widths, 2)
|
| 9 |
+
# Use advanced indexing to compute the individual components
|
| 10 |
+
diff = distances[..., None] - offset
|
| 11 |
+
else:
|
| 12 |
+
# if Gaussian functions are centered, use offsets to compute widths
|
| 13 |
+
coeff = -0.5 / torch.pow(offset, 2)
|
| 14 |
+
# if Gaussian functions are centered, no offset is subtracted
|
| 15 |
+
diff = distances[..., None]
|
| 16 |
+
# compute smear distance values
|
| 17 |
+
gauss = torch.exp(coeff * torch.pow(diff, 2))
|
| 18 |
+
return gauss
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
class GaussianBasis(nn.Module):
|
| 22 |
+
def __init__(
|
| 23 |
+
self, start=0.0, stop=5.0, n_gaussians=50, centered=False, trainable=False
|
| 24 |
+
):
|
| 25 |
+
super(GaussianBasis, self).__init__()
|
| 26 |
+
# compute offset and width of Gaussian functions
|
| 27 |
+
offset = torch.linspace(start, stop, n_gaussians)
|
| 28 |
+
widths = torch.FloatTensor((offset[1] - offset[0]) * torch.ones_like(offset))
|
| 29 |
+
if trainable:
|
| 30 |
+
self.width = nn.Parameter(widths)
|
| 31 |
+
self.offsets = nn.Parameter(offset)
|
| 32 |
+
else:
|
| 33 |
+
self.register_buffer("width", widths)
|
| 34 |
+
self.register_buffer("offsets", offset)
|
| 35 |
+
self.centered = centered
|
| 36 |
+
|
| 37 |
+
def forward(self, distances):
|
| 38 |
+
"""Compute smeared-gaussian distance values.
|
| 39 |
+
|
| 40 |
+
Args:
|
| 41 |
+
distances (torch.Tensor): interatomic distance values of
|
| 42 |
+
(N_b x N_at x N_nbh) shape.
|
| 43 |
+
|
| 44 |
+
Returns:
|
| 45 |
+
torch.Tensor: layer output of (N_b x N_at x N_nbh x N_g) shape.
|
| 46 |
+
|
| 47 |
+
"""
|
| 48 |
+
return gaussian_smearing(
|
| 49 |
+
distances, self.offsets, self.width, centered=self.centered
|
| 50 |
+
)
|
3_epc/displacements/group_8/reconstruction/aohamiltonian/pred_ham_std/src/deeph/from_schnetpack/license.txt
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
The code in this folder was obtained from "https://github.com/atomistic-machine-learning/schnetpack", which has the following license:
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
COPYRIGHT
|
| 5 |
+
|
| 6 |
+
Copyright (c) 2018 Kristof Schütt, Michael Gastegger, Pan Kessel, Kim Nicoli
|
| 7 |
+
|
| 8 |
+
All other contributions:
|
| 9 |
+
Copyright (c) 2018, the respective contributors.
|
| 10 |
+
All rights reserved.
|
| 11 |
+
|
| 12 |
+
Each contributor holds copyright over their respective contributions.
|
| 13 |
+
The project versioning (Git) records all such contribution source information.
|
| 14 |
+
|
| 15 |
+
LICENSE
|
| 16 |
+
|
| 17 |
+
The MIT License
|
| 18 |
+
|
| 19 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 20 |
+
of this software and associated documentation files (the "Software"), to deal
|
| 21 |
+
in the Software without restriction, including without limitation the rights
|
| 22 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 23 |
+
copies of the Software, and to permit persons to whom the Software is
|
| 24 |
+
furnished to do so, subject to the following conditions:
|
| 25 |
+
|
| 26 |
+
The above copyright notice and this permission notice shall be included in all
|
| 27 |
+
copies or substantial portions of the Software.
|
| 28 |
+
|
| 29 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 30 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 31 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 32 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 33 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 34 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
| 35 |
+
SOFTWARE.
|
3_epc/displacements/group_8/reconstruction/aohamiltonian/pred_ham_std/src/deeph/graph.py
ADDED
|
@@ -0,0 +1,934 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import collections
|
| 2 |
+
import itertools
|
| 3 |
+
import os
|
| 4 |
+
import json
|
| 5 |
+
import warnings
|
| 6 |
+
import math
|
| 7 |
+
|
| 8 |
+
import torch
|
| 9 |
+
import torch_geometric
|
| 10 |
+
from torch_geometric.data import Data, Batch
|
| 11 |
+
import numpy as np
|
| 12 |
+
import h5py
|
| 13 |
+
|
| 14 |
+
from .model import get_spherical_from_cartesian, SphericalHarmonics
|
| 15 |
+
from .from_pymatgen import find_neighbors, _one_to_three, _compute_cube_index, _three_to_one
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
"""
|
| 19 |
+
The function _spherical_harmonics below is come from "https://github.com/e3nn/e3nn", which has the MIT License below
|
| 20 |
+
|
| 21 |
+
---------------------------------------------------------------------------
|
| 22 |
+
MIT License
|
| 23 |
+
|
| 24 |
+
Euclidean neural networks (e3nn) Copyright (c) 2020, The Regents of the
|
| 25 |
+
University of California, through Lawrence Berkeley National Laboratory
|
| 26 |
+
(subject to receipt of any required approvals from the U.S. Dept. of Energy),
|
| 27 |
+
Ecole Polytechnique Federale de Lausanne (EPFL), Free University of Berlin
|
| 28 |
+
and Kostiantyn Lapchevskyi. All rights reserved.
|
| 29 |
+
|
| 30 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 31 |
+
of this software and associated documentation files (the "Software"), to deal
|
| 32 |
+
in the Software without restriction, including without limitation the rights to use,
|
| 33 |
+
copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
|
| 34 |
+
Software, and to permit persons to whom the Software is furnished to do so,
|
| 35 |
+
subject to the following conditions:
|
| 36 |
+
|
| 37 |
+
The above copyright notice and this permission notice shall be included in all
|
| 38 |
+
copies or substantial portions of the Software.
|
| 39 |
+
|
| 40 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 41 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 42 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 43 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 44 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 45 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
| 46 |
+
SOFTWARE.
|
| 47 |
+
"""
|
| 48 |
+
def _spherical_harmonics(lmax: int, x: torch.Tensor, y: torch.Tensor, z: torch.Tensor) -> torch.Tensor:
|
| 49 |
+
sh_0_0 = torch.ones_like(x)
|
| 50 |
+
if lmax == 0:
|
| 51 |
+
return torch.stack([
|
| 52 |
+
sh_0_0,
|
| 53 |
+
], dim=-1)
|
| 54 |
+
|
| 55 |
+
sh_1_0 = x
|
| 56 |
+
sh_1_1 = y
|
| 57 |
+
sh_1_2 = z
|
| 58 |
+
if lmax == 1:
|
| 59 |
+
return torch.stack([
|
| 60 |
+
sh_0_0,
|
| 61 |
+
sh_1_0, sh_1_1, sh_1_2
|
| 62 |
+
], dim=-1)
|
| 63 |
+
|
| 64 |
+
sh_2_0 = math.sqrt(3.0) * x * z
|
| 65 |
+
sh_2_1 = math.sqrt(3.0) * x * y
|
| 66 |
+
y2 = y.pow(2)
|
| 67 |
+
x2z2 = x.pow(2) + z.pow(2)
|
| 68 |
+
sh_2_2 = y2 - 0.5 * x2z2
|
| 69 |
+
sh_2_3 = math.sqrt(3.0) * y * z
|
| 70 |
+
sh_2_4 = math.sqrt(3.0) / 2.0 * (z.pow(2) - x.pow(2))
|
| 71 |
+
|
| 72 |
+
if lmax == 2:
|
| 73 |
+
return torch.stack([
|
| 74 |
+
sh_0_0,
|
| 75 |
+
sh_1_0, sh_1_1, sh_1_2,
|
| 76 |
+
sh_2_0, sh_2_1, sh_2_2, sh_2_3, sh_2_4
|
| 77 |
+
], dim=-1)
|
| 78 |
+
|
| 79 |
+
sh_3_0 = math.sqrt(5.0 / 6.0) * (sh_2_0 * z + sh_2_4 * x)
|
| 80 |
+
sh_3_1 = math.sqrt(5.0) * sh_2_0 * y
|
| 81 |
+
sh_3_2 = math.sqrt(3.0 / 8.0) * (4.0 * y2 - x2z2) * x
|
| 82 |
+
sh_3_3 = 0.5 * y * (2.0 * y2 - 3.0 * x2z2)
|
| 83 |
+
sh_3_4 = math.sqrt(3.0 / 8.0) * z * (4.0 * y2 - x2z2)
|
| 84 |
+
sh_3_5 = math.sqrt(5.0) * sh_2_4 * y
|
| 85 |
+
sh_3_6 = math.sqrt(5.0 / 6.0) * (sh_2_4 * z - sh_2_0 * x)
|
| 86 |
+
|
| 87 |
+
if lmax == 3:
|
| 88 |
+
return torch.stack([
|
| 89 |
+
sh_0_0,
|
| 90 |
+
sh_1_0, sh_1_1, sh_1_2,
|
| 91 |
+
sh_2_0, sh_2_1, sh_2_2, sh_2_3, sh_2_4,
|
| 92 |
+
sh_3_0, sh_3_1, sh_3_2, sh_3_3, sh_3_4, sh_3_5, sh_3_6
|
| 93 |
+
], dim=-1)
|
| 94 |
+
|
| 95 |
+
sh_4_0 = 0.935414346693485*sh_3_0*z + 0.935414346693485*sh_3_6*x
|
| 96 |
+
sh_4_1 = 0.661437827766148*sh_3_0*y + 0.810092587300982*sh_3_1*z + 0.810092587300983*sh_3_5*x
|
| 97 |
+
sh_4_2 = -0.176776695296637*sh_3_0*z + 0.866025403784439*sh_3_1*y + 0.684653196881458*sh_3_2*z + 0.684653196881457*sh_3_4*x + 0.176776695296637*sh_3_6*x
|
| 98 |
+
sh_4_3 = -0.306186217847897*sh_3_1*z + 0.968245836551855*sh_3_2*y + 0.790569415042095*sh_3_3*x + 0.306186217847897*sh_3_5*x
|
| 99 |
+
sh_4_4 = -0.612372435695795*sh_3_2*x + sh_3_3*y - 0.612372435695795*sh_3_4*z
|
| 100 |
+
sh_4_5 = -0.306186217847897*sh_3_1*x + 0.790569415042096*sh_3_3*z + 0.968245836551854*sh_3_4*y - 0.306186217847897*sh_3_5*z
|
| 101 |
+
sh_4_6 = -0.176776695296637*sh_3_0*x - 0.684653196881457*sh_3_2*x + 0.684653196881457*sh_3_4*z + 0.866025403784439*sh_3_5*y - 0.176776695296637*sh_3_6*z
|
| 102 |
+
sh_4_7 = -0.810092587300982*sh_3_1*x + 0.810092587300982*sh_3_5*z + 0.661437827766148*sh_3_6*y
|
| 103 |
+
sh_4_8 = -0.935414346693485*sh_3_0*x + 0.935414346693486*sh_3_6*z
|
| 104 |
+
if lmax == 4:
|
| 105 |
+
return torch.stack([
|
| 106 |
+
sh_0_0,
|
| 107 |
+
sh_1_0, sh_1_1, sh_1_2,
|
| 108 |
+
sh_2_0, sh_2_1, sh_2_2, sh_2_3, sh_2_4,
|
| 109 |
+
sh_3_0, sh_3_1, sh_3_2, sh_3_3, sh_3_4, sh_3_5, sh_3_6,
|
| 110 |
+
sh_4_0, sh_4_1, sh_4_2, sh_4_3, sh_4_4, sh_4_5, sh_4_6, sh_4_7, sh_4_8
|
| 111 |
+
], dim=-1)
|
| 112 |
+
|
| 113 |
+
sh_5_0 = 0.948683298050513*sh_4_0*z + 0.948683298050513*sh_4_8*x
|
| 114 |
+
sh_5_1 = 0.6*sh_4_0*y + 0.848528137423857*sh_4_1*z + 0.848528137423858*sh_4_7*x
|
| 115 |
+
sh_5_2 = -0.14142135623731*sh_4_0*z + 0.8*sh_4_1*y + 0.748331477354788*sh_4_2*z + 0.748331477354788*sh_4_6*x + 0.14142135623731*sh_4_8*x
|
| 116 |
+
sh_5_3 = -0.244948974278318*sh_4_1*z + 0.916515138991168*sh_4_2*y + 0.648074069840786*sh_4_3*z + 0.648074069840787*sh_4_5*x + 0.244948974278318*sh_4_7*x
|
| 117 |
+
sh_5_4 = -0.346410161513776*sh_4_2*z + 0.979795897113272*sh_4_3*y + 0.774596669241484*sh_4_4*x + 0.346410161513776*sh_4_6*x
|
| 118 |
+
sh_5_5 = -0.632455532033676*sh_4_3*x + sh_4_4*y - 0.632455532033676*sh_4_5*z
|
| 119 |
+
sh_5_6 = -0.346410161513776*sh_4_2*x + 0.774596669241483*sh_4_4*z + 0.979795897113273*sh_4_5*y - 0.346410161513776*sh_4_6*z
|
| 120 |
+
sh_5_7 = -0.244948974278318*sh_4_1*x - 0.648074069840787*sh_4_3*x + 0.648074069840786*sh_4_5*z + 0.916515138991169*sh_4_6*y - 0.244948974278318*sh_4_7*z
|
| 121 |
+
sh_5_8 = -0.141421356237309*sh_4_0*x - 0.748331477354788*sh_4_2*x + 0.748331477354788*sh_4_6*z + 0.8*sh_4_7*y - 0.141421356237309*sh_4_8*z
|
| 122 |
+
sh_5_9 = -0.848528137423857*sh_4_1*x + 0.848528137423857*sh_4_7*z + 0.6*sh_4_8*y
|
| 123 |
+
sh_5_10 = -0.948683298050513*sh_4_0*x + 0.948683298050513*sh_4_8*z
|
| 124 |
+
if lmax == 5:
|
| 125 |
+
return torch.stack([
|
| 126 |
+
sh_0_0,
|
| 127 |
+
sh_1_0, sh_1_1, sh_1_2,
|
| 128 |
+
sh_2_0, sh_2_1, sh_2_2, sh_2_3, sh_2_4,
|
| 129 |
+
sh_3_0, sh_3_1, sh_3_2, sh_3_3, sh_3_4, sh_3_5, sh_3_6,
|
| 130 |
+
sh_4_0, sh_4_1, sh_4_2, sh_4_3, sh_4_4, sh_4_5, sh_4_6, sh_4_7, sh_4_8,
|
| 131 |
+
sh_5_0, sh_5_1, sh_5_2, sh_5_3, sh_5_4, sh_5_5, sh_5_6, sh_5_7, sh_5_8, sh_5_9, sh_5_10
|
| 132 |
+
], dim=-1)
|
| 133 |
+
|
| 134 |
+
sh_6_0 = 0.957427107756337*sh_5_0*z + 0.957427107756338*sh_5_10*x
|
| 135 |
+
sh_6_1 = 0.552770798392565*sh_5_0*y + 0.874007373475125*sh_5_1*z + 0.874007373475125*sh_5_9*x
|
| 136 |
+
sh_6_2 = -0.117851130197757*sh_5_0*z + 0.745355992499929*sh_5_1*y + 0.117851130197758*sh_5_10*x + 0.790569415042094*sh_5_2*z + 0.790569415042093*sh_5_8*x
|
| 137 |
+
sh_6_3 = -0.204124145231931*sh_5_1*z + 0.866025403784437*sh_5_2*y + 0.707106781186546*sh_5_3*z + 0.707106781186547*sh_5_7*x + 0.204124145231931*sh_5_9*x
|
| 138 |
+
sh_6_4 = -0.288675134594813*sh_5_2*z + 0.942809041582062*sh_5_3*y + 0.623609564462323*sh_5_4*z + 0.623609564462322*sh_5_6*x + 0.288675134594812*sh_5_8*x
|
| 139 |
+
sh_6_5 = -0.372677996249965*sh_5_3*z + 0.986013297183268*sh_5_4*y + 0.763762615825972*sh_5_5*x + 0.372677996249964*sh_5_7*x
|
| 140 |
+
sh_6_6 = -0.645497224367901*sh_5_4*x + sh_5_5*y - 0.645497224367902*sh_5_6*z
|
| 141 |
+
sh_6_7 = -0.372677996249964*sh_5_3*x + 0.763762615825972*sh_5_5*z + 0.986013297183269*sh_5_6*y - 0.372677996249965*sh_5_7*z
|
| 142 |
+
sh_6_8 = -0.288675134594813*sh_5_2*x - 0.623609564462323*sh_5_4*x + 0.623609564462323*sh_5_6*z + 0.942809041582062*sh_5_7*y - 0.288675134594812*sh_5_8*z
|
| 143 |
+
sh_6_9 = -0.20412414523193*sh_5_1*x - 0.707106781186546*sh_5_3*x + 0.707106781186547*sh_5_7*z + 0.866025403784438*sh_5_8*y - 0.204124145231931*sh_5_9*z
|
| 144 |
+
sh_6_10 = -0.117851130197757*sh_5_0*x - 0.117851130197757*sh_5_10*z - 0.790569415042094*sh_5_2*x + 0.790569415042093*sh_5_8*z + 0.745355992499929*sh_5_9*y
|
| 145 |
+
sh_6_11 = -0.874007373475124*sh_5_1*x + 0.552770798392566*sh_5_10*y + 0.874007373475125*sh_5_9*z
|
| 146 |
+
sh_6_12 = -0.957427107756337*sh_5_0*x + 0.957427107756336*sh_5_10*z
|
| 147 |
+
if lmax == 6:
|
| 148 |
+
return torch.stack([
|
| 149 |
+
sh_0_0,
|
| 150 |
+
sh_1_0, sh_1_1, sh_1_2,
|
| 151 |
+
sh_2_0, sh_2_1, sh_2_2, sh_2_3, sh_2_4,
|
| 152 |
+
sh_3_0, sh_3_1, sh_3_2, sh_3_3, sh_3_4, sh_3_5, sh_3_6,
|
| 153 |
+
sh_4_0, sh_4_1, sh_4_2, sh_4_3, sh_4_4, sh_4_5, sh_4_6, sh_4_7, sh_4_8,
|
| 154 |
+
sh_5_0, sh_5_1, sh_5_2, sh_5_3, sh_5_4, sh_5_5, sh_5_6, sh_5_7, sh_5_8, sh_5_9, sh_5_10,
|
| 155 |
+
sh_6_0, sh_6_1, sh_6_2, sh_6_3, sh_6_4, sh_6_5, sh_6_6, sh_6_7, sh_6_8, sh_6_9, sh_6_10, sh_6_11, sh_6_12
|
| 156 |
+
], dim=-1)
|
| 157 |
+
|
| 158 |
+
sh_7_0 = 0.963624111659433*sh_6_0*z + 0.963624111659432*sh_6_12*x
|
| 159 |
+
sh_7_1 = 0.515078753637713*sh_6_0*y + 0.892142571199771*sh_6_1*z + 0.892142571199771*sh_6_11*x
|
| 160 |
+
sh_7_2 = -0.101015254455221*sh_6_0*z + 0.699854212223765*sh_6_1*y + 0.82065180664829*sh_6_10*x + 0.101015254455222*sh_6_12*x + 0.82065180664829*sh_6_2*z
|
| 161 |
+
sh_7_3 = -0.174963553055942*sh_6_1*z + 0.174963553055941*sh_6_11*x + 0.82065180664829*sh_6_2*y + 0.749149177264394*sh_6_3*z + 0.749149177264394*sh_6_9*x
|
| 162 |
+
sh_7_4 = 0.247435829652697*sh_6_10*x - 0.247435829652697*sh_6_2*z + 0.903507902905251*sh_6_3*y + 0.677630927178938*sh_6_4*z + 0.677630927178938*sh_6_8*x
|
| 163 |
+
sh_7_5 = -0.31943828249997*sh_6_3*z + 0.95831484749991*sh_6_4*y + 0.606091526731326*sh_6_5*z + 0.606091526731326*sh_6_7*x + 0.31943828249997*sh_6_9*x
|
| 164 |
+
sh_7_6 = -0.391230398217976*sh_6_4*z + 0.989743318610787*sh_6_5*y + 0.755928946018454*sh_6_6*x + 0.391230398217975*sh_6_8*x
|
| 165 |
+
sh_7_7 = -0.654653670707977*sh_6_5*x + sh_6_6*y - 0.654653670707978*sh_6_7*z
|
| 166 |
+
sh_7_8 = -0.391230398217976*sh_6_4*x + 0.755928946018455*sh_6_6*z + 0.989743318610787*sh_6_7*y - 0.391230398217975*sh_6_8*z
|
| 167 |
+
sh_7_9 = -0.31943828249997*sh_6_3*x - 0.606091526731327*sh_6_5*x + 0.606091526731326*sh_6_7*z + 0.95831484749991*sh_6_8*y - 0.31943828249997*sh_6_9*z
|
| 168 |
+
sh_7_10 = -0.247435829652697*sh_6_10*z - 0.247435829652697*sh_6_2*x - 0.677630927178938*sh_6_4*x + 0.677630927178938*sh_6_8*z + 0.903507902905251*sh_6_9*y
|
| 169 |
+
sh_7_11 = -0.174963553055942*sh_6_1*x + 0.820651806648289*sh_6_10*y - 0.174963553055941*sh_6_11*z - 0.749149177264394*sh_6_3*x + 0.749149177264394*sh_6_9*z
|
| 170 |
+
sh_7_12 = -0.101015254455221*sh_6_0*x + 0.82065180664829*sh_6_10*z + 0.699854212223766*sh_6_11*y - 0.101015254455221*sh_6_12*z - 0.82065180664829*sh_6_2*x
|
| 171 |
+
sh_7_13 = -0.892142571199772*sh_6_1*x + 0.892142571199772*sh_6_11*z + 0.515078753637713*sh_6_12*y
|
| 172 |
+
sh_7_14 = -0.963624111659431*sh_6_0*x + 0.963624111659433*sh_6_12*z
|
| 173 |
+
if lmax == 7:
|
| 174 |
+
return torch.stack([
|
| 175 |
+
sh_0_0,
|
| 176 |
+
sh_1_0, sh_1_1, sh_1_2,
|
| 177 |
+
sh_2_0, sh_2_1, sh_2_2, sh_2_3, sh_2_4,
|
| 178 |
+
sh_3_0, sh_3_1, sh_3_2, sh_3_3, sh_3_4, sh_3_5, sh_3_6,
|
| 179 |
+
sh_4_0, sh_4_1, sh_4_2, sh_4_3, sh_4_4, sh_4_5, sh_4_6, sh_4_7, sh_4_8,
|
| 180 |
+
sh_5_0, sh_5_1, sh_5_2, sh_5_3, sh_5_4, sh_5_5, sh_5_6, sh_5_7, sh_5_8, sh_5_9, sh_5_10,
|
| 181 |
+
sh_6_0, sh_6_1, sh_6_2, sh_6_3, sh_6_4, sh_6_5, sh_6_6, sh_6_7, sh_6_8, sh_6_9, sh_6_10, sh_6_11, sh_6_12,
|
| 182 |
+
sh_7_0, sh_7_1, sh_7_2, sh_7_3, sh_7_4, sh_7_5, sh_7_6, sh_7_7, sh_7_8, sh_7_9, sh_7_10, sh_7_11, sh_7_12, sh_7_13, sh_7_14
|
| 183 |
+
], dim=-1)
|
| 184 |
+
|
| 185 |
+
sh_8_0 = 0.968245836551854*sh_7_0*z + 0.968245836551853*sh_7_14*x
|
| 186 |
+
sh_8_1 = 0.484122918275928*sh_7_0*y + 0.90571104663684*sh_7_1*z + 0.90571104663684*sh_7_13*x
|
| 187 |
+
sh_8_2 = -0.0883883476483189*sh_7_0*z + 0.661437827766148*sh_7_1*y + 0.843171097702002*sh_7_12*x + 0.088388347648318*sh_7_14*x + 0.843171097702003*sh_7_2*z
|
| 188 |
+
sh_8_3 = -0.153093108923948*sh_7_1*z + 0.7806247497998*sh_7_11*x + 0.153093108923949*sh_7_13*x + 0.7806247497998*sh_7_2*y + 0.780624749799799*sh_7_3*z
|
| 189 |
+
sh_8_4 = 0.718070330817253*sh_7_10*x + 0.21650635094611*sh_7_12*x - 0.21650635094611*sh_7_2*z + 0.866025403784439*sh_7_3*y + 0.718070330817254*sh_7_4*z
|
| 190 |
+
sh_8_5 = 0.279508497187474*sh_7_11*x - 0.279508497187474*sh_7_3*z + 0.927024810886958*sh_7_4*y + 0.655505530106345*sh_7_5*z + 0.655505530106344*sh_7_9*x
|
| 191 |
+
sh_8_6 = 0.342326598440729*sh_7_10*x - 0.342326598440729*sh_7_4*z + 0.968245836551854*sh_7_5*y + 0.592927061281572*sh_7_6*z + 0.592927061281571*sh_7_8*x
|
| 192 |
+
sh_8_7 = -0.405046293650492*sh_7_5*z + 0.992156741649221*sh_7_6*y + 0.75*sh_7_7*x + 0.405046293650492*sh_7_9*x
|
| 193 |
+
sh_8_8 = -0.661437827766148*sh_7_6*x + sh_7_7*y - 0.661437827766148*sh_7_8*z
|
| 194 |
+
sh_8_9 = -0.405046293650492*sh_7_5*x + 0.75*sh_7_7*z + 0.992156741649221*sh_7_8*y - 0.405046293650491*sh_7_9*z
|
| 195 |
+
sh_8_10 = -0.342326598440728*sh_7_10*z - 0.342326598440729*sh_7_4*x - 0.592927061281571*sh_7_6*x + 0.592927061281571*sh_7_8*z + 0.968245836551855*sh_7_9*y
|
| 196 |
+
sh_8_11 = 0.927024810886958*sh_7_10*y - 0.279508497187474*sh_7_11*z - 0.279508497187474*sh_7_3*x - 0.655505530106345*sh_7_5*x + 0.655505530106345*sh_7_9*z
|
| 197 |
+
sh_8_12 = 0.718070330817253*sh_7_10*z + 0.866025403784439*sh_7_11*y - 0.216506350946109*sh_7_12*z - 0.216506350946109*sh_7_2*x - 0.718070330817254*sh_7_4*x
|
| 198 |
+
sh_8_13 = -0.153093108923948*sh_7_1*x + 0.7806247497998*sh_7_11*z + 0.7806247497998*sh_7_12*y - 0.153093108923948*sh_7_13*z - 0.780624749799799*sh_7_3*x
|
| 199 |
+
sh_8_14 = -0.0883883476483179*sh_7_0*x + 0.843171097702002*sh_7_12*z + 0.661437827766147*sh_7_13*y - 0.088388347648319*sh_7_14*z - 0.843171097702002*sh_7_2*x
|
| 200 |
+
sh_8_15 = -0.90571104663684*sh_7_1*x + 0.90571104663684*sh_7_13*z + 0.484122918275927*sh_7_14*y
|
| 201 |
+
sh_8_16 = -0.968245836551853*sh_7_0*x + 0.968245836551855*sh_7_14*z
|
| 202 |
+
if lmax == 8:
|
| 203 |
+
return torch.stack([
|
| 204 |
+
sh_0_0,
|
| 205 |
+
sh_1_0, sh_1_1, sh_1_2,
|
| 206 |
+
sh_2_0, sh_2_1, sh_2_2, sh_2_3, sh_2_4,
|
| 207 |
+
sh_3_0, sh_3_1, sh_3_2, sh_3_3, sh_3_4, sh_3_5, sh_3_6,
|
| 208 |
+
sh_4_0, sh_4_1, sh_4_2, sh_4_3, sh_4_4, sh_4_5, sh_4_6, sh_4_7, sh_4_8,
|
| 209 |
+
sh_5_0, sh_5_1, sh_5_2, sh_5_3, sh_5_4, sh_5_5, sh_5_6, sh_5_7, sh_5_8, sh_5_9, sh_5_10,
|
| 210 |
+
sh_6_0, sh_6_1, sh_6_2, sh_6_3, sh_6_4, sh_6_5, sh_6_6, sh_6_7, sh_6_8, sh_6_9, sh_6_10, sh_6_11, sh_6_12,
|
| 211 |
+
sh_7_0, sh_7_1, sh_7_2, sh_7_3, sh_7_4, sh_7_5, sh_7_6, sh_7_7, sh_7_8, sh_7_9, sh_7_10, sh_7_11, sh_7_12, sh_7_13, sh_7_14,
|
| 212 |
+
sh_8_0, sh_8_1, sh_8_2, sh_8_3, sh_8_4, sh_8_5, sh_8_6, sh_8_7, sh_8_8, sh_8_9, sh_8_10, sh_8_11, sh_8_12, sh_8_13, sh_8_14, sh_8_15, sh_8_16
|
| 213 |
+
], dim=-1)
|
| 214 |
+
|
| 215 |
+
sh_9_0 = 0.97182531580755*sh_8_0*z + 0.971825315807551*sh_8_16*x
|
| 216 |
+
sh_9_1 = 0.458122847290851*sh_8_0*y + 0.916245694581702*sh_8_1*z + 0.916245694581702*sh_8_15*x
|
| 217 |
+
sh_9_2 = -0.078567420131839*sh_8_0*z + 0.62853936105471*sh_8_1*y + 0.86066296582387*sh_8_14*x + 0.0785674201318385*sh_8_16*x + 0.860662965823871*sh_8_2*z
|
| 218 |
+
sh_9_3 = -0.136082763487955*sh_8_1*z + 0.805076485899413*sh_8_13*x + 0.136082763487954*sh_8_15*x + 0.74535599249993*sh_8_2*y + 0.805076485899413*sh_8_3*z
|
| 219 |
+
sh_9_4 = 0.749485420179558*sh_8_12*x + 0.192450089729875*sh_8_14*x - 0.192450089729876*sh_8_2*z + 0.831479419283099*sh_8_3*y + 0.749485420179558*sh_8_4*z
|
| 220 |
+
sh_9_5 = 0.693888666488711*sh_8_11*x + 0.248451997499977*sh_8_13*x - 0.248451997499976*sh_8_3*z + 0.895806416477617*sh_8_4*y + 0.69388866648871*sh_8_5*z
|
| 221 |
+
sh_9_6 = 0.638284738504225*sh_8_10*x + 0.304290309725092*sh_8_12*x - 0.304290309725092*sh_8_4*z + 0.942809041582063*sh_8_5*y + 0.638284738504225*sh_8_6*z
|
| 222 |
+
sh_9_7 = 0.360041149911548*sh_8_11*x - 0.360041149911548*sh_8_5*z + 0.974996043043569*sh_8_6*y + 0.582671582316751*sh_8_7*z + 0.582671582316751*sh_8_9*x
|
| 223 |
+
sh_9_8 = 0.415739709641549*sh_8_10*x - 0.415739709641549*sh_8_6*z + 0.993807989999906*sh_8_7*y + 0.74535599249993*sh_8_8*x
|
| 224 |
+
sh_9_9 = -0.66666666666666666667*sh_8_7*x + sh_8_8*y - 0.66666666666666666667*sh_8_9*z
|
| 225 |
+
sh_9_10 = -0.415739709641549*sh_8_10*z - 0.415739709641549*sh_8_6*x + 0.74535599249993*sh_8_8*z + 0.993807989999906*sh_8_9*y
|
| 226 |
+
sh_9_11 = 0.974996043043568*sh_8_10*y - 0.360041149911547*sh_8_11*z - 0.360041149911548*sh_8_5*x - 0.582671582316751*sh_8_7*x + 0.582671582316751*sh_8_9*z
|
| 227 |
+
sh_9_12 = 0.638284738504225*sh_8_10*z + 0.942809041582063*sh_8_11*y - 0.304290309725092*sh_8_12*z - 0.304290309725092*sh_8_4*x - 0.638284738504225*sh_8_6*x
|
| 228 |
+
sh_9_13 = 0.693888666488711*sh_8_11*z + 0.895806416477617*sh_8_12*y - 0.248451997499977*sh_8_13*z - 0.248451997499977*sh_8_3*x - 0.693888666488711*sh_8_5*x
|
| 229 |
+
sh_9_14 = 0.749485420179558*sh_8_12*z + 0.831479419283098*sh_8_13*y - 0.192450089729875*sh_8_14*z - 0.192450089729875*sh_8_2*x - 0.749485420179558*sh_8_4*x
|
| 230 |
+
sh_9_15 = -0.136082763487954*sh_8_1*x + 0.805076485899413*sh_8_13*z + 0.745355992499929*sh_8_14*y - 0.136082763487955*sh_8_15*z - 0.805076485899413*sh_8_3*x
|
| 231 |
+
sh_9_16 = -0.0785674201318389*sh_8_0*x + 0.86066296582387*sh_8_14*z + 0.628539361054709*sh_8_15*y - 0.0785674201318387*sh_8_16*z - 0.860662965823871*sh_8_2*x
|
| 232 |
+
sh_9_17 = -0.9162456945817*sh_8_1*x + 0.916245694581702*sh_8_15*z + 0.458122847290851*sh_8_16*y
|
| 233 |
+
sh_9_18 = -0.97182531580755*sh_8_0*x + 0.97182531580755*sh_8_16*z
|
| 234 |
+
if lmax == 9:
|
| 235 |
+
return torch.stack([
|
| 236 |
+
sh_0_0,
|
| 237 |
+
sh_1_0, sh_1_1, sh_1_2,
|
| 238 |
+
sh_2_0, sh_2_1, sh_2_2, sh_2_3, sh_2_4,
|
| 239 |
+
sh_3_0, sh_3_1, sh_3_2, sh_3_3, sh_3_4, sh_3_5, sh_3_6,
|
| 240 |
+
sh_4_0, sh_4_1, sh_4_2, sh_4_3, sh_4_4, sh_4_5, sh_4_6, sh_4_7, sh_4_8,
|
| 241 |
+
sh_5_0, sh_5_1, sh_5_2, sh_5_3, sh_5_4, sh_5_5, sh_5_6, sh_5_7, sh_5_8, sh_5_9, sh_5_10,
|
| 242 |
+
sh_6_0, sh_6_1, sh_6_2, sh_6_3, sh_6_4, sh_6_5, sh_6_6, sh_6_7, sh_6_8, sh_6_9, sh_6_10, sh_6_11, sh_6_12,
|
| 243 |
+
sh_7_0, sh_7_1, sh_7_2, sh_7_3, sh_7_4, sh_7_5, sh_7_6, sh_7_7, sh_7_8, sh_7_9, sh_7_10, sh_7_11, sh_7_12, sh_7_13, sh_7_14,
|
| 244 |
+
sh_8_0, sh_8_1, sh_8_2, sh_8_3, sh_8_4, sh_8_5, sh_8_6, sh_8_7, sh_8_8, sh_8_9, sh_8_10, sh_8_11, sh_8_12, sh_8_13, sh_8_14, sh_8_15, sh_8_16,
|
| 245 |
+
sh_9_0, sh_9_1, sh_9_2, sh_9_3, sh_9_4, sh_9_5, sh_9_6, sh_9_7, sh_9_8, sh_9_9, sh_9_10, sh_9_11, sh_9_12, sh_9_13, sh_9_14, sh_9_15, sh_9_16, sh_9_17, sh_9_18
|
| 246 |
+
], dim=-1)
|
| 247 |
+
|
| 248 |
+
sh_10_0 = 0.974679434480897*sh_9_0*z + 0.974679434480897*sh_9_18*x
|
| 249 |
+
sh_10_1 = 0.435889894354067*sh_9_0*y + 0.924662100445347*sh_9_1*z + 0.924662100445347*sh_9_17*x
|
| 250 |
+
sh_10_2 = -0.0707106781186546*sh_9_0*z + 0.6*sh_9_1*y + 0.874642784226796*sh_9_16*x + 0.070710678118655*sh_9_18*x + 0.874642784226795*sh_9_2*z
|
| 251 |
+
sh_10_3 = -0.122474487139159*sh_9_1*z + 0.824621125123533*sh_9_15*x + 0.122474487139159*sh_9_17*x + 0.714142842854285*sh_9_2*y + 0.824621125123533*sh_9_3*z
|
| 252 |
+
sh_10_4 = 0.774596669241484*sh_9_14*x + 0.173205080756887*sh_9_16*x - 0.173205080756888*sh_9_2*z + 0.8*sh_9_3*y + 0.774596669241483*sh_9_4*z
|
| 253 |
+
sh_10_5 = 0.724568837309472*sh_9_13*x + 0.223606797749979*sh_9_15*x - 0.223606797749979*sh_9_3*z + 0.866025403784438*sh_9_4*y + 0.724568837309472*sh_9_5*z
|
| 254 |
+
sh_10_6 = 0.674536878161602*sh_9_12*x + 0.273861278752583*sh_9_14*x - 0.273861278752583*sh_9_4*z + 0.916515138991168*sh_9_5*y + 0.674536878161602*sh_9_6*z
|
| 255 |
+
sh_10_7 = 0.62449979983984*sh_9_11*x + 0.324037034920393*sh_9_13*x - 0.324037034920393*sh_9_5*z + 0.953939201416946*sh_9_6*y + 0.62449979983984*sh_9_7*z
|
| 256 |
+
sh_10_8 = 0.574456264653803*sh_9_10*x + 0.374165738677394*sh_9_12*x - 0.374165738677394*sh_9_6*z + 0.979795897113272*sh_9_7*y + 0.574456264653803*sh_9_8*z
|
| 257 |
+
sh_10_9 = 0.424264068711928*sh_9_11*x - 0.424264068711929*sh_9_7*z + 0.99498743710662*sh_9_8*y + 0.741619848709567*sh_9_9*x
|
| 258 |
+
sh_10_10 = -0.670820393249937*sh_9_10*z - 0.670820393249937*sh_9_8*x + sh_9_9*y
|
| 259 |
+
sh_10_11 = 0.99498743710662*sh_9_10*y - 0.424264068711929*sh_9_11*z - 0.424264068711929*sh_9_7*x + 0.741619848709567*sh_9_9*z
|
| 260 |
+
sh_10_12 = 0.574456264653803*sh_9_10*z + 0.979795897113272*sh_9_11*y - 0.374165738677395*sh_9_12*z - 0.374165738677394*sh_9_6*x - 0.574456264653803*sh_9_8*x
|
| 261 |
+
sh_10_13 = 0.62449979983984*sh_9_11*z + 0.953939201416946*sh_9_12*y - 0.324037034920393*sh_9_13*z - 0.324037034920393*sh_9_5*x - 0.62449979983984*sh_9_7*x
|
| 262 |
+
sh_10_14 = 0.674536878161602*sh_9_12*z + 0.916515138991168*sh_9_13*y - 0.273861278752583*sh_9_14*z - 0.273861278752583*sh_9_4*x - 0.674536878161603*sh_9_6*x
|
| 263 |
+
sh_10_15 = 0.724568837309472*sh_9_13*z + 0.866025403784439*sh_9_14*y - 0.223606797749979*sh_9_15*z - 0.223606797749979*sh_9_3*x - 0.724568837309472*sh_9_5*x
|
| 264 |
+
sh_10_16 = 0.774596669241484*sh_9_14*z + 0.8*sh_9_15*y - 0.173205080756888*sh_9_16*z - 0.173205080756887*sh_9_2*x - 0.774596669241484*sh_9_4*x
|
| 265 |
+
sh_10_17 = -0.12247448713916*sh_9_1*x + 0.824621125123532*sh_9_15*z + 0.714142842854285*sh_9_16*y - 0.122474487139158*sh_9_17*z - 0.824621125123533*sh_9_3*x
|
| 266 |
+
sh_10_18 = -0.0707106781186548*sh_9_0*x + 0.874642784226796*sh_9_16*z + 0.6*sh_9_17*y - 0.0707106781186546*sh_9_18*z - 0.874642784226796*sh_9_2*x
|
| 267 |
+
sh_10_19 = -0.924662100445348*sh_9_1*x + 0.924662100445347*sh_9_17*z + 0.435889894354068*sh_9_18*y
|
| 268 |
+
sh_10_20 = -0.974679434480898*sh_9_0*x + 0.974679434480896*sh_9_18*z
|
| 269 |
+
if lmax == 10:
|
| 270 |
+
return torch.stack([
|
| 271 |
+
sh_0_0,
|
| 272 |
+
sh_1_0, sh_1_1, sh_1_2,
|
| 273 |
+
sh_2_0, sh_2_1, sh_2_2, sh_2_3, sh_2_4,
|
| 274 |
+
sh_3_0, sh_3_1, sh_3_2, sh_3_3, sh_3_4, sh_3_5, sh_3_6,
|
| 275 |
+
sh_4_0, sh_4_1, sh_4_2, sh_4_3, sh_4_4, sh_4_5, sh_4_6, sh_4_7, sh_4_8,
|
| 276 |
+
sh_5_0, sh_5_1, sh_5_2, sh_5_3, sh_5_4, sh_5_5, sh_5_6, sh_5_7, sh_5_8, sh_5_9, sh_5_10,
|
| 277 |
+
sh_6_0, sh_6_1, sh_6_2, sh_6_3, sh_6_4, sh_6_5, sh_6_6, sh_6_7, sh_6_8, sh_6_9, sh_6_10, sh_6_11, sh_6_12,
|
| 278 |
+
sh_7_0, sh_7_1, sh_7_2, sh_7_3, sh_7_4, sh_7_5, sh_7_6, sh_7_7, sh_7_8, sh_7_9, sh_7_10, sh_7_11, sh_7_12, sh_7_13, sh_7_14,
|
| 279 |
+
sh_8_0, sh_8_1, sh_8_2, sh_8_3, sh_8_4, sh_8_5, sh_8_6, sh_8_7, sh_8_8, sh_8_9, sh_8_10, sh_8_11, sh_8_12, sh_8_13, sh_8_14, sh_8_15, sh_8_16,
|
| 280 |
+
sh_9_0, sh_9_1, sh_9_2, sh_9_3, sh_9_4, sh_9_5, sh_9_6, sh_9_7, sh_9_8, sh_9_9, sh_9_10, sh_9_11, sh_9_12, sh_9_13, sh_9_14, sh_9_15, sh_9_16, sh_9_17, sh_9_18,
|
| 281 |
+
sh_10_0, sh_10_1, sh_10_2, sh_10_3, sh_10_4, sh_10_5, sh_10_6, sh_10_7, sh_10_8, sh_10_9, sh_10_10, sh_10_11, sh_10_12, sh_10_13, sh_10_14, sh_10_15, sh_10_16, sh_10_17, sh_10_18, sh_10_19, sh_10_20
|
| 282 |
+
], dim=-1)
|
| 283 |
+
|
| 284 |
+
sh_11_0 = 0.977008420918394*sh_10_0*z + 0.977008420918394*sh_10_20*x
|
| 285 |
+
sh_11_1 = 0.416597790450531*sh_10_0*y + 0.9315409787236*sh_10_1*z + 0.931540978723599*sh_10_19*x
|
| 286 |
+
sh_11_2 = -0.0642824346533223*sh_10_0*z + 0.574959574576069*sh_10_1*y + 0.88607221316445*sh_10_18*x + 0.886072213164452*sh_10_2*z + 0.0642824346533226*sh_10_20*x
|
| 287 |
+
sh_11_3 = -0.111340442853781*sh_10_1*z + 0.84060190949577*sh_10_17*x + 0.111340442853781*sh_10_19*x + 0.686348585024614*sh_10_2*y + 0.840601909495769*sh_10_3*z
|
| 288 |
+
sh_11_4 = 0.795129803842541*sh_10_16*x + 0.157459164324444*sh_10_18*x - 0.157459164324443*sh_10_2*z + 0.771389215839871*sh_10_3*y + 0.795129803842541*sh_10_4*z
|
| 289 |
+
sh_11_5 = 0.74965556829412*sh_10_15*x + 0.203278907045435*sh_10_17*x - 0.203278907045436*sh_10_3*z + 0.838140405208444*sh_10_4*y + 0.74965556829412*sh_10_5*z
|
| 290 |
+
sh_11_6 = 0.70417879021953*sh_10_14*x + 0.248964798865985*sh_10_16*x - 0.248964798865985*sh_10_4*z + 0.890723542830247*sh_10_5*y + 0.704178790219531*sh_10_6*z
|
| 291 |
+
sh_11_7 = 0.658698943008611*sh_10_13*x + 0.294579122654903*sh_10_15*x - 0.294579122654903*sh_10_5*z + 0.9315409787236*sh_10_6*y + 0.658698943008611*sh_10_7*z
|
| 292 |
+
sh_11_8 = 0.613215343783275*sh_10_12*x + 0.340150671524904*sh_10_14*x - 0.340150671524904*sh_10_6*z + 0.962091385841669*sh_10_7*y + 0.613215343783274*sh_10_8*z
|
| 293 |
+
sh_11_9 = 0.567727090763491*sh_10_11*x + 0.385694607919935*sh_10_13*x - 0.385694607919935*sh_10_7*z + 0.983332166035633*sh_10_8*y + 0.56772709076349*sh_10_9*z
|
| 294 |
+
sh_11_10 = 0.738548945875997*sh_10_10*x + 0.431219680932052*sh_10_12*x - 0.431219680932052*sh_10_8*z + 0.995859195463938*sh_10_9*y
|
| 295 |
+
sh_11_11 = sh_10_10*y - 0.674199862463242*sh_10_11*z - 0.674199862463243*sh_10_9*x
|
| 296 |
+
sh_11_12 = 0.738548945875996*sh_10_10*z + 0.995859195463939*sh_10_11*y - 0.431219680932052*sh_10_12*z - 0.431219680932053*sh_10_8*x
|
| 297 |
+
sh_11_13 = 0.567727090763491*sh_10_11*z + 0.983332166035634*sh_10_12*y - 0.385694607919935*sh_10_13*z - 0.385694607919935*sh_10_7*x - 0.567727090763491*sh_10_9*x
|
| 298 |
+
sh_11_14 = 0.613215343783275*sh_10_12*z + 0.96209138584167*sh_10_13*y - 0.340150671524904*sh_10_14*z - 0.340150671524904*sh_10_6*x - 0.613215343783274*sh_10_8*x
|
| 299 |
+
sh_11_15 = 0.658698943008611*sh_10_13*z + 0.9315409787236*sh_10_14*y - 0.294579122654903*sh_10_15*z - 0.294579122654903*sh_10_5*x - 0.65869894300861*sh_10_7*x
|
| 300 |
+
sh_11_16 = 0.70417879021953*sh_10_14*z + 0.890723542830246*sh_10_15*y - 0.248964798865985*sh_10_16*z - 0.248964798865985*sh_10_4*x - 0.70417879021953*sh_10_6*x
|
| 301 |
+
sh_11_17 = 0.749655568294121*sh_10_15*z + 0.838140405208444*sh_10_16*y - 0.203278907045436*sh_10_17*z - 0.203278907045435*sh_10_3*x - 0.749655568294119*sh_10_5*x
|
| 302 |
+
sh_11_18 = 0.79512980384254*sh_10_16*z + 0.77138921583987*sh_10_17*y - 0.157459164324443*sh_10_18*z - 0.157459164324444*sh_10_2*x - 0.795129803842541*sh_10_4*x
|
| 303 |
+
sh_11_19 = -0.111340442853782*sh_10_1*x + 0.84060190949577*sh_10_17*z + 0.686348585024614*sh_10_18*y - 0.111340442853781*sh_10_19*z - 0.840601909495769*sh_10_3*x
|
| 304 |
+
sh_11_20 = -0.0642824346533226*sh_10_0*x + 0.886072213164451*sh_10_18*z + 0.57495957457607*sh_10_19*y - 0.886072213164451*sh_10_2*x - 0.0642824346533228*sh_10_20*z
|
| 305 |
+
sh_11_21 = -0.9315409787236*sh_10_1*x + 0.931540978723599*sh_10_19*z + 0.416597790450531*sh_10_20*y
|
| 306 |
+
sh_11_22 = -0.977008420918393*sh_10_0*x + 0.977008420918393*sh_10_20*z
|
| 307 |
+
return torch.stack([
|
| 308 |
+
sh_0_0,
|
| 309 |
+
sh_1_0, sh_1_1, sh_1_2,
|
| 310 |
+
sh_2_0, sh_2_1, sh_2_2, sh_2_3, sh_2_4,
|
| 311 |
+
sh_3_0, sh_3_1, sh_3_2, sh_3_3, sh_3_4, sh_3_5, sh_3_6,
|
| 312 |
+
sh_4_0, sh_4_1, sh_4_2, sh_4_3, sh_4_4, sh_4_5, sh_4_6, sh_4_7, sh_4_8,
|
| 313 |
+
sh_5_0, sh_5_1, sh_5_2, sh_5_3, sh_5_4, sh_5_5, sh_5_6, sh_5_7, sh_5_8, sh_5_9, sh_5_10,
|
| 314 |
+
sh_6_0, sh_6_1, sh_6_2, sh_6_3, sh_6_4, sh_6_5, sh_6_6, sh_6_7, sh_6_8, sh_6_9, sh_6_10, sh_6_11, sh_6_12,
|
| 315 |
+
sh_7_0, sh_7_1, sh_7_2, sh_7_3, sh_7_4, sh_7_5, sh_7_6, sh_7_7, sh_7_8, sh_7_9, sh_7_10, sh_7_11, sh_7_12, sh_7_13, sh_7_14,
|
| 316 |
+
sh_8_0, sh_8_1, sh_8_2, sh_8_3, sh_8_4, sh_8_5, sh_8_6, sh_8_7, sh_8_8, sh_8_9, sh_8_10, sh_8_11, sh_8_12, sh_8_13, sh_8_14, sh_8_15, sh_8_16,
|
| 317 |
+
sh_9_0, sh_9_1, sh_9_2, sh_9_3, sh_9_4, sh_9_5, sh_9_6, sh_9_7, sh_9_8, sh_9_9, sh_9_10, sh_9_11, sh_9_12, sh_9_13, sh_9_14, sh_9_15, sh_9_16, sh_9_17, sh_9_18,
|
| 318 |
+
sh_10_0, sh_10_1, sh_10_2, sh_10_3, sh_10_4, sh_10_5, sh_10_6, sh_10_7, sh_10_8, sh_10_9, sh_10_10, sh_10_11, sh_10_12, sh_10_13, sh_10_14, sh_10_15, sh_10_16, sh_10_17, sh_10_18, sh_10_19, sh_10_20,
|
| 319 |
+
sh_11_0, sh_11_1, sh_11_2, sh_11_3, sh_11_4, sh_11_5, sh_11_6, sh_11_7, sh_11_8, sh_11_9, sh_11_10, sh_11_11, sh_11_12, sh_11_13, sh_11_14, sh_11_15, sh_11_16, sh_11_17, sh_11_18, sh_11_19, sh_11_20, sh_11_21, sh_11_22
|
| 320 |
+
], dim=-1)
|
| 321 |
+
|
| 322 |
+
|
| 323 |
+
def collate_fn(graph_list):
|
| 324 |
+
return Collater(if_lcmp=True)(graph_list)
|
| 325 |
+
|
| 326 |
+
|
| 327 |
+
class Collater:
|
| 328 |
+
def __init__(self, if_lcmp):
|
| 329 |
+
self.if_lcmp = if_lcmp
|
| 330 |
+
self.flag_pyg2 = (torch_geometric.__version__[0] == '2')
|
| 331 |
+
|
| 332 |
+
def __call__(self, graph_list):
|
| 333 |
+
if self.if_lcmp:
|
| 334 |
+
flag_dict = hasattr(graph_list[0], 'subgraph_dict')
|
| 335 |
+
if self.flag_pyg2:
|
| 336 |
+
assert flag_dict, 'Please generate the graph file with the current version of PyG'
|
| 337 |
+
batch = Batch.from_data_list(graph_list)
|
| 338 |
+
|
| 339 |
+
subgraph_atom_idx_batch = []
|
| 340 |
+
subgraph_edge_idx_batch = []
|
| 341 |
+
subgraph_edge_ang_batch = []
|
| 342 |
+
subgraph_index_batch = []
|
| 343 |
+
if flag_dict:
|
| 344 |
+
for index_batch in range(len(graph_list)):
|
| 345 |
+
(subgraph_atom_idx, subgraph_edge_idx, subgraph_edge_ang,
|
| 346 |
+
subgraph_index) = graph_list[index_batch].subgraph_dict.values()
|
| 347 |
+
if self.flag_pyg2:
|
| 348 |
+
subgraph_atom_idx_batch.append(subgraph_atom_idx + batch._slice_dict['x'][index_batch])
|
| 349 |
+
subgraph_edge_idx_batch.append(subgraph_edge_idx + batch._slice_dict['edge_attr'][index_batch])
|
| 350 |
+
subgraph_index_batch.append(subgraph_index + batch._slice_dict['edge_attr'][index_batch] * 2)
|
| 351 |
+
else:
|
| 352 |
+
subgraph_atom_idx_batch.append(subgraph_atom_idx + batch.__slices__['x'][index_batch])
|
| 353 |
+
subgraph_edge_idx_batch.append(subgraph_edge_idx + batch.__slices__['edge_attr'][index_batch])
|
| 354 |
+
subgraph_index_batch.append(subgraph_index + batch.__slices__['edge_attr'][index_batch] * 2)
|
| 355 |
+
subgraph_edge_ang_batch.append(subgraph_edge_ang)
|
| 356 |
+
else:
|
| 357 |
+
for index_batch, (subgraph_atom_idx, subgraph_edge_idx,
|
| 358 |
+
subgraph_edge_ang, subgraph_index) in enumerate(batch.subgraph):
|
| 359 |
+
subgraph_atom_idx_batch.append(subgraph_atom_idx + batch.__slices__['x'][index_batch])
|
| 360 |
+
subgraph_edge_idx_batch.append(subgraph_edge_idx + batch.__slices__['edge_attr'][index_batch])
|
| 361 |
+
subgraph_edge_ang_batch.append(subgraph_edge_ang)
|
| 362 |
+
subgraph_index_batch.append(subgraph_index + batch.__slices__['edge_attr'][index_batch] * 2)
|
| 363 |
+
|
| 364 |
+
subgraph_atom_idx_batch = torch.cat(subgraph_atom_idx_batch, dim=0)
|
| 365 |
+
subgraph_edge_idx_batch = torch.cat(subgraph_edge_idx_batch, dim=0)
|
| 366 |
+
subgraph_edge_ang_batch = torch.cat(subgraph_edge_ang_batch, dim=0)
|
| 367 |
+
subgraph_index_batch = torch.cat(subgraph_index_batch, dim=0)
|
| 368 |
+
|
| 369 |
+
subgraph = (subgraph_atom_idx_batch, subgraph_edge_idx_batch, subgraph_edge_ang_batch, subgraph_index_batch)
|
| 370 |
+
|
| 371 |
+
return batch, subgraph
|
| 372 |
+
else:
|
| 373 |
+
return Batch.from_data_list(graph_list)
|
| 374 |
+
|
| 375 |
+
|
| 376 |
+
def load_orbital_types(path, return_orbital_types=False):
|
| 377 |
+
orbital_types = []
|
| 378 |
+
with open(path) as f:
|
| 379 |
+
line = f.readline()
|
| 380 |
+
while line:
|
| 381 |
+
orbital_types.append(list(map(int, line.split())))
|
| 382 |
+
line = f.readline()
|
| 383 |
+
atom_num_orbital = [sum(map(lambda x: 2 * x + 1,atom_orbital_types)) for atom_orbital_types in orbital_types]
|
| 384 |
+
if return_orbital_types:
|
| 385 |
+
return atom_num_orbital, orbital_types
|
| 386 |
+
else:
|
| 387 |
+
return atom_num_orbital
|
| 388 |
+
|
| 389 |
+
|
| 390 |
+
"""
|
| 391 |
+
The function get_graph below is extended from "https://github.com/materialsproject/pymatgen", which has the MIT License below
|
| 392 |
+
|
| 393 |
+
---------------------------------------------------------------------------
|
| 394 |
+
The MIT License (MIT)
|
| 395 |
+
Copyright (c) 2011-2012 MIT & The Regents of the University of California, through Lawrence Berkeley National Laboratory
|
| 396 |
+
|
| 397 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
| 398 |
+
this software and associated documentation files (the "Software"), to deal in
|
| 399 |
+
the Software without restriction, including without limitation the rights to
|
| 400 |
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
| 401 |
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
| 402 |
+
subject to the following conditions:
|
| 403 |
+
|
| 404 |
+
The above copyright notice and this permission notice shall be included in all
|
| 405 |
+
copies or substantial portions of the Software.
|
| 406 |
+
|
| 407 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 408 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
| 409 |
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
| 410 |
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
| 411 |
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
| 412 |
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
| 413 |
+
"""
|
| 414 |
+
def get_graph(cart_coords, frac_coords, numbers, stru_id, r, max_num_nbr, numerical_tol, lattice,
|
| 415 |
+
default_dtype_torch, tb_folder, interface, num_l, create_from_DFT, if_lcmp_graph,
|
| 416 |
+
separate_onsite, target='hamiltonian', huge_structure=False, only_get_R_list=False, if_new_sp=False,
|
| 417 |
+
if_require_grad=False, fid_rc=None, **kwargs):
|
| 418 |
+
assert target in ['hamiltonian', 'phiVdphi', 'density_matrix', 'O_ij', 'E_ij', 'E_i']
|
| 419 |
+
if target == 'density_matrix' or target == 'O_ij':
|
| 420 |
+
assert interface == 'h5' or interface == 'h5_rc_only'
|
| 421 |
+
if target == 'E_ij':
|
| 422 |
+
assert interface == 'h5'
|
| 423 |
+
assert create_from_DFT is True
|
| 424 |
+
assert separate_onsite is True
|
| 425 |
+
if target == 'E_i':
|
| 426 |
+
assert interface == 'h5'
|
| 427 |
+
assert if_lcmp_graph is False
|
| 428 |
+
assert separate_onsite is True
|
| 429 |
+
if create_from_DFT:
|
| 430 |
+
assert tb_folder is not None
|
| 431 |
+
assert max_num_nbr == 0
|
| 432 |
+
if interface == 'h5_rc_only' and target == 'E_ij':
|
| 433 |
+
raise NotImplementedError
|
| 434 |
+
elif interface == 'h5' or (interface == 'h5_rc_only' and target != 'E_ij'):
|
| 435 |
+
key_atom_list = [[] for _ in range(len(numbers))]
|
| 436 |
+
edge_idx, edge_fea, edge_idx_first = [], [], []
|
| 437 |
+
if if_lcmp_graph:
|
| 438 |
+
atom_idx_connect, edge_idx_connect = [], []
|
| 439 |
+
edge_idx_connect_cursor = 0
|
| 440 |
+
if target == 'E_ij':
|
| 441 |
+
fid = h5py.File(os.path.join(tb_folder, 'E_delta_ee_ij.h5'), 'r')
|
| 442 |
+
else:
|
| 443 |
+
if if_require_grad:
|
| 444 |
+
fid = fid_rc
|
| 445 |
+
else:
|
| 446 |
+
fid = h5py.File(os.path.join(tb_folder, 'rc.h5'), 'r')
|
| 447 |
+
for k in fid.keys():
|
| 448 |
+
key = json.loads(k)
|
| 449 |
+
key_tensor = torch.tensor([key[0], key[1], key[2], key[3] - 1, key[4] - 1]) # (R, i, j) i and j is 0-based index
|
| 450 |
+
if separate_onsite:
|
| 451 |
+
if key[0] == 0 and key[1] == 0 and key[2] == 0 and key[3] == key[4]:
|
| 452 |
+
continue
|
| 453 |
+
key_atom_list[key[3] - 1].append(key_tensor)
|
| 454 |
+
if target != 'E_ij' and not if_require_grad:
|
| 455 |
+
fid.close()
|
| 456 |
+
|
| 457 |
+
for index_first, (cart_coord, keys_tensor) in enumerate(zip(cart_coords, key_atom_list)):
|
| 458 |
+
keys_tensor = torch.stack(keys_tensor)
|
| 459 |
+
cart_coords_j = cart_coords[keys_tensor[:, 4]] + keys_tensor[:, :3].type(default_dtype_torch).to(cart_coords.device) @ lattice.to(cart_coords.device)
|
| 460 |
+
dist = torch.norm(cart_coords_j - cart_coord[None, :], dim=1)
|
| 461 |
+
len_nn = keys_tensor.shape[0]
|
| 462 |
+
edge_idx_first.extend([index_first] * len_nn)
|
| 463 |
+
edge_idx.extend(keys_tensor[:, 4].tolist())
|
| 464 |
+
|
| 465 |
+
edge_fea_single = torch.cat([dist.view(-1, 1), cart_coord.view(1, 3).expand(len_nn, 3)], dim=-1)
|
| 466 |
+
edge_fea_single = torch.cat([edge_fea_single, cart_coords_j, cart_coords[keys_tensor[:, 4]]], dim=-1)
|
| 467 |
+
edge_fea.append(edge_fea_single)
|
| 468 |
+
|
| 469 |
+
if if_lcmp_graph:
|
| 470 |
+
atom_idx_connect.append(keys_tensor[:, 4])
|
| 471 |
+
edge_idx_connect.append(range(edge_idx_connect_cursor, edge_idx_connect_cursor + len_nn))
|
| 472 |
+
edge_idx_connect_cursor += len_nn
|
| 473 |
+
|
| 474 |
+
edge_fea = torch.cat(edge_fea).type(default_dtype_torch)
|
| 475 |
+
edge_idx = torch.stack([torch.LongTensor(edge_idx_first), torch.LongTensor(edge_idx)])
|
| 476 |
+
else:
|
| 477 |
+
raise NotImplemented
|
| 478 |
+
else:
|
| 479 |
+
cart_coords_np = cart_coords.detach().numpy()
|
| 480 |
+
frac_coords_np = frac_coords.detach().numpy()
|
| 481 |
+
lattice_np = lattice.detach().numpy()
|
| 482 |
+
num_atom = cart_coords.shape[0]
|
| 483 |
+
|
| 484 |
+
center_coords_min = np.min(cart_coords_np, axis=0)
|
| 485 |
+
center_coords_max = np.max(cart_coords_np, axis=0)
|
| 486 |
+
global_min = center_coords_min - r - numerical_tol
|
| 487 |
+
global_max = center_coords_max + r + numerical_tol
|
| 488 |
+
global_min_torch = torch.tensor(global_min)
|
| 489 |
+
global_max_torch = torch.tensor(global_max)
|
| 490 |
+
|
| 491 |
+
reciprocal_lattice = np.linalg.inv(lattice_np).T * 2 * np.pi
|
| 492 |
+
recp_len = np.sqrt(np.sum(reciprocal_lattice ** 2, axis=1))
|
| 493 |
+
maxr = np.ceil((r + 0.15) * recp_len / (2 * np.pi))
|
| 494 |
+
nmin = np.floor(np.min(frac_coords_np, axis=0)) - maxr
|
| 495 |
+
nmax = np.ceil(np.max(frac_coords_np, axis=0)) + maxr
|
| 496 |
+
all_ranges = [np.arange(x, y, dtype='int64') for x, y in zip(nmin, nmax)]
|
| 497 |
+
images = torch.tensor(list(itertools.product(*all_ranges))).type_as(lattice)
|
| 498 |
+
|
| 499 |
+
if only_get_R_list:
|
| 500 |
+
return images
|
| 501 |
+
|
| 502 |
+
coords = (images @ lattice)[:, None, :] + cart_coords[None, :, :]
|
| 503 |
+
indices = torch.arange(num_atom).unsqueeze(0).expand(images.shape[0], num_atom)
|
| 504 |
+
valid_index_bool = coords.gt(global_min_torch) * coords.lt(global_max_torch)
|
| 505 |
+
valid_index_bool = valid_index_bool.all(dim=-1)
|
| 506 |
+
valid_coords = coords[valid_index_bool]
|
| 507 |
+
valid_indices = indices[valid_index_bool]
|
| 508 |
+
|
| 509 |
+
|
| 510 |
+
valid_coords_np = valid_coords.detach().numpy()
|
| 511 |
+
all_cube_index = _compute_cube_index(valid_coords_np, global_min, r)
|
| 512 |
+
nx, ny, nz = _compute_cube_index(global_max, global_min, r) + 1
|
| 513 |
+
all_cube_index = _three_to_one(all_cube_index, ny, nz)
|
| 514 |
+
site_cube_index = _three_to_one(_compute_cube_index(cart_coords_np, global_min, r), ny, nz)
|
| 515 |
+
cube_to_coords_index = collections.defaultdict(list) # type: Dict[int, List]
|
| 516 |
+
|
| 517 |
+
for index, cart_coord in enumerate(all_cube_index.ravel()):
|
| 518 |
+
cube_to_coords_index[cart_coord].append(index)
|
| 519 |
+
|
| 520 |
+
site_neighbors = find_neighbors(site_cube_index, nx, ny, nz)
|
| 521 |
+
|
| 522 |
+
edge_idx, edge_fea, edge_idx_first = [], [], []
|
| 523 |
+
if if_lcmp_graph:
|
| 524 |
+
atom_idx_connect, edge_idx_connect = [], []
|
| 525 |
+
edge_idx_connect_cursor = 0
|
| 526 |
+
for index_first, (cart_coord, j) in enumerate(zip(cart_coords, site_neighbors)):
|
| 527 |
+
l1 = np.array(_three_to_one(j, ny, nz), dtype=int).ravel()
|
| 528 |
+
ks = [k for k in l1 if k in cube_to_coords_index]
|
| 529 |
+
nn_coords_index = np.concatenate([cube_to_coords_index[k] for k in ks], axis=0)
|
| 530 |
+
nn_coords = valid_coords[nn_coords_index]
|
| 531 |
+
nn_indices = valid_indices[nn_coords_index]
|
| 532 |
+
dist = torch.norm(nn_coords - cart_coord[None, :], dim=1)
|
| 533 |
+
|
| 534 |
+
if separate_onsite is False:
|
| 535 |
+
nn_coords = nn_coords.squeeze()
|
| 536 |
+
nn_indices = nn_indices.squeeze()
|
| 537 |
+
dist = dist.squeeze()
|
| 538 |
+
else:
|
| 539 |
+
nonzero_index = dist.nonzero(as_tuple=False)
|
| 540 |
+
nn_coords = nn_coords[nonzero_index]
|
| 541 |
+
nn_coords = nn_coords.squeeze(1)
|
| 542 |
+
nn_indices = nn_indices[nonzero_index].view(-1)
|
| 543 |
+
dist = dist[nonzero_index].view(-1)
|
| 544 |
+
|
| 545 |
+
if max_num_nbr > 0:
|
| 546 |
+
if len(dist) >= max_num_nbr:
|
| 547 |
+
dist_top, index_top = dist.topk(max_num_nbr, largest=False, sorted=True)
|
| 548 |
+
edge_idx.extend(nn_indices[index_top])
|
| 549 |
+
if if_lcmp_graph:
|
| 550 |
+
atom_idx_connect.append(nn_indices[index_top])
|
| 551 |
+
edge_idx_first.extend([index_first] * len(index_top))
|
| 552 |
+
edge_fea_single = torch.cat([dist_top.view(-1, 1), cart_coord.view(1, 3).expand(len(index_top), 3)], dim=-1)
|
| 553 |
+
edge_fea_single = torch.cat([edge_fea_single, nn_coords[index_top], cart_coords[nn_indices[index_top]]], dim=-1)
|
| 554 |
+
edge_fea.append(edge_fea_single)
|
| 555 |
+
else:
|
| 556 |
+
warnings.warn("Can not find a number of max_num_nbr atoms within radius")
|
| 557 |
+
edge_idx.extend(nn_indices)
|
| 558 |
+
if if_lcmp_graph:
|
| 559 |
+
atom_idx_connect.append(nn_indices)
|
| 560 |
+
edge_idx_first.extend([index_first] * len(nn_indices))
|
| 561 |
+
edge_fea_single = torch.cat([dist.view(-1, 1), cart_coord.view(1, 3).expand(len(nn_indices), 3)], dim=-1)
|
| 562 |
+
edge_fea_single = torch.cat([edge_fea_single, nn_coords, cart_coords[nn_indices]], dim=-1)
|
| 563 |
+
edge_fea.append(edge_fea_single)
|
| 564 |
+
else:
|
| 565 |
+
index_top = dist.lt(r + numerical_tol)
|
| 566 |
+
edge_idx.extend(nn_indices[index_top])
|
| 567 |
+
if if_lcmp_graph:
|
| 568 |
+
atom_idx_connect.append(nn_indices[index_top])
|
| 569 |
+
edge_idx_first.extend([index_first] * len(nn_indices[index_top]))
|
| 570 |
+
edge_fea_single = torch.cat([dist[index_top].view(-1, 1), cart_coord.view(1, 3).expand(len(nn_indices[index_top]), 3)], dim=-1)
|
| 571 |
+
edge_fea_single = torch.cat([edge_fea_single, nn_coords[index_top], cart_coords[nn_indices[index_top]]], dim=-1)
|
| 572 |
+
edge_fea.append(edge_fea_single)
|
| 573 |
+
if if_lcmp_graph:
|
| 574 |
+
edge_idx_connect.append(range(edge_idx_connect_cursor, edge_idx_connect_cursor + len(atom_idx_connect[-1])))
|
| 575 |
+
edge_idx_connect_cursor += len(atom_idx_connect[-1])
|
| 576 |
+
|
| 577 |
+
|
| 578 |
+
edge_fea = torch.cat(edge_fea).type(default_dtype_torch)
|
| 579 |
+
edge_idx_first = torch.LongTensor(edge_idx_first)
|
| 580 |
+
edge_idx = torch.stack([edge_idx_first, torch.LongTensor(edge_idx)])
|
| 581 |
+
|
| 582 |
+
|
| 583 |
+
if tb_folder is not None:
|
| 584 |
+
if target == 'E_ij':
|
| 585 |
+
read_file_list = ['E_ij.h5', 'E_delta_ee_ij.h5', 'E_xc_ij.h5']
|
| 586 |
+
graph_key_list = ['E_ij', 'E_delta_ee_ij', 'E_xc_ij']
|
| 587 |
+
read_terms_dict = {}
|
| 588 |
+
for read_file, graph_key in zip(read_file_list, graph_key_list):
|
| 589 |
+
read_terms = {}
|
| 590 |
+
fid = h5py.File(os.path.join(tb_folder, read_file), 'r')
|
| 591 |
+
for k, v in fid.items():
|
| 592 |
+
key = json.loads(k)
|
| 593 |
+
key = (key[0], key[1], key[2], key[3] - 1, key[4] - 1)
|
| 594 |
+
read_terms[key] = torch.tensor(v[...], dtype=default_dtype_torch)
|
| 595 |
+
read_terms_dict[graph_key] = read_terms
|
| 596 |
+
fid.close()
|
| 597 |
+
|
| 598 |
+
local_rotation_dict = {}
|
| 599 |
+
if if_require_grad:
|
| 600 |
+
fid = fid_rc
|
| 601 |
+
else:
|
| 602 |
+
fid = h5py.File(os.path.join(tb_folder, 'rc.h5'), 'r')
|
| 603 |
+
for k, v in fid.items():
|
| 604 |
+
key = json.loads(k)
|
| 605 |
+
key = (key[0], key[1], key[2], key[3] - 1, key[4] - 1) # (R, i, j) i and j is 0-based index
|
| 606 |
+
if if_require_grad:
|
| 607 |
+
local_rotation_dict[key] = v
|
| 608 |
+
else:
|
| 609 |
+
local_rotation_dict[key] = torch.tensor(v, dtype=default_dtype_torch)
|
| 610 |
+
if not if_require_grad:
|
| 611 |
+
fid.close()
|
| 612 |
+
elif target == 'E_i':
|
| 613 |
+
read_file_list = ['E_i.h5']
|
| 614 |
+
graph_key_list = ['E_i']
|
| 615 |
+
read_terms_dict = {}
|
| 616 |
+
for read_file, graph_key in zip(read_file_list, graph_key_list):
|
| 617 |
+
read_terms = {}
|
| 618 |
+
fid = h5py.File(os.path.join(tb_folder, read_file), 'r')
|
| 619 |
+
for k, v in fid.items():
|
| 620 |
+
index_i = int(k) # index_i is 0-based index
|
| 621 |
+
read_terms[index_i] = torch.tensor(v[...], dtype=default_dtype_torch)
|
| 622 |
+
fid.close()
|
| 623 |
+
read_terms_dict[graph_key] = read_terms
|
| 624 |
+
else:
|
| 625 |
+
if interface == 'h5' or interface == 'h5_rc_only':
|
| 626 |
+
atom_num_orbital = load_orbital_types(os.path.join(tb_folder, 'orbital_types.dat'))
|
| 627 |
+
|
| 628 |
+
if interface == 'h5':
|
| 629 |
+
with open(os.path.join(tb_folder, 'info.json'), 'r') as info_f:
|
| 630 |
+
info_dict = json.load(info_f)
|
| 631 |
+
spinful = info_dict["isspinful"]
|
| 632 |
+
|
| 633 |
+
if interface == 'h5':
|
| 634 |
+
if target == 'hamiltonian':
|
| 635 |
+
read_file_list = ['rh.h5']
|
| 636 |
+
graph_key_list = ['term_real']
|
| 637 |
+
elif target == 'phiVdphi':
|
| 638 |
+
read_file_list = ['rphiVdphi.h5']
|
| 639 |
+
graph_key_list = ['term_real']
|
| 640 |
+
elif target == 'density_matrix':
|
| 641 |
+
read_file_list = ['rdm.h5']
|
| 642 |
+
graph_key_list = ['term_real']
|
| 643 |
+
elif target == 'O_ij':
|
| 644 |
+
read_file_list = ['rh.h5', 'rdm.h5', 'rvna.h5', 'rvdee.h5', 'rvxc.h5']
|
| 645 |
+
graph_key_list = ['rh', 'rdm', 'rvna', 'rvdee', 'rvxc']
|
| 646 |
+
else:
|
| 647 |
+
raise ValueError('Unknown prediction target: {}'.format(target))
|
| 648 |
+
read_terms_dict = {}
|
| 649 |
+
for read_file, graph_key in zip(read_file_list, graph_key_list):
|
| 650 |
+
read_terms = {}
|
| 651 |
+
fid = h5py.File(os.path.join(tb_folder, read_file), 'r')
|
| 652 |
+
for k, v in fid.items():
|
| 653 |
+
key = json.loads(k)
|
| 654 |
+
key = (key[0], key[1], key[2], key[3] - 1, key[4] - 1)
|
| 655 |
+
if spinful:
|
| 656 |
+
num_orbital_row = atom_num_orbital[key[3]]
|
| 657 |
+
num_orbital_column = atom_num_orbital[key[4]]
|
| 658 |
+
# soc block order:
|
| 659 |
+
# 1 3
|
| 660 |
+
# 4 2
|
| 661 |
+
if target == 'phiVdphi':
|
| 662 |
+
raise NotImplementedError
|
| 663 |
+
else:
|
| 664 |
+
read_value = torch.stack([
|
| 665 |
+
torch.tensor(v[:num_orbital_row, :num_orbital_column].real, dtype=default_dtype_torch),
|
| 666 |
+
torch.tensor(v[:num_orbital_row, :num_orbital_column].imag, dtype=default_dtype_torch),
|
| 667 |
+
torch.tensor(v[num_orbital_row:, num_orbital_column:].real, dtype=default_dtype_torch),
|
| 668 |
+
torch.tensor(v[num_orbital_row:, num_orbital_column:].imag, dtype=default_dtype_torch),
|
| 669 |
+
torch.tensor(v[:num_orbital_row, num_orbital_column:].real, dtype=default_dtype_torch),
|
| 670 |
+
torch.tensor(v[:num_orbital_row, num_orbital_column:].imag, dtype=default_dtype_torch),
|
| 671 |
+
torch.tensor(v[num_orbital_row:, :num_orbital_column].real, dtype=default_dtype_torch),
|
| 672 |
+
torch.tensor(v[num_orbital_row:, :num_orbital_column].imag, dtype=default_dtype_torch)
|
| 673 |
+
], dim=-1)
|
| 674 |
+
read_terms[key] = read_value
|
| 675 |
+
else:
|
| 676 |
+
read_terms[key] = torch.tensor(v[...], dtype=default_dtype_torch)
|
| 677 |
+
read_terms_dict[graph_key] = read_terms
|
| 678 |
+
fid.close()
|
| 679 |
+
|
| 680 |
+
local_rotation_dict = {}
|
| 681 |
+
if if_require_grad:
|
| 682 |
+
fid = fid_rc
|
| 683 |
+
else:
|
| 684 |
+
fid = h5py.File(os.path.join(tb_folder, 'rc.h5'), 'r')
|
| 685 |
+
for k, v in fid.items():
|
| 686 |
+
key = json.loads(k)
|
| 687 |
+
key = (key[0], key[1], key[2], key[3] - 1, key[4] - 1) # (R, i, j) i and j is 0-based index
|
| 688 |
+
if if_require_grad:
|
| 689 |
+
local_rotation_dict[key] = v
|
| 690 |
+
else:
|
| 691 |
+
local_rotation_dict[key] = torch.tensor(v[...], dtype=default_dtype_torch)
|
| 692 |
+
if not if_require_grad:
|
| 693 |
+
fid.close()
|
| 694 |
+
|
| 695 |
+
max_num_orbital = max(atom_num_orbital)
|
| 696 |
+
|
| 697 |
+
elif interface == 'npz' or interface == 'npz_rc_only':
|
| 698 |
+
spinful = False
|
| 699 |
+
atom_num_orbital = load_orbital_types(os.path.join(tb_folder, 'orbital_types.dat'))
|
| 700 |
+
|
| 701 |
+
if interface == 'npz':
|
| 702 |
+
graph_key_list = ['term_real']
|
| 703 |
+
read_terms_dict = {'term_real': {}}
|
| 704 |
+
hopping_dict_read = np.load(os.path.join(tb_folder, 'rh.npz'))
|
| 705 |
+
for k, v in hopping_dict_read.items():
|
| 706 |
+
key = json.loads(k)
|
| 707 |
+
key = (key[0], key[1], key[2], key[3] - 1, key[4] - 1) # (R, i, j) i and j is 0-based index
|
| 708 |
+
read_terms_dict['term_real'][key] = torch.tensor(v, dtype=default_dtype_torch)
|
| 709 |
+
|
| 710 |
+
local_rotation_dict = {}
|
| 711 |
+
local_rotation_dict_read = np.load(os.path.join(tb_folder, 'rc.npz'))
|
| 712 |
+
for k, v in local_rotation_dict_read.items():
|
| 713 |
+
key = json.loads(k)
|
| 714 |
+
key = (key[0], key[1], key[2], key[3] - 1, key[4] - 1)
|
| 715 |
+
local_rotation_dict[key] = torch.tensor(v, dtype=default_dtype_torch)
|
| 716 |
+
|
| 717 |
+
max_num_orbital = max(atom_num_orbital)
|
| 718 |
+
else:
|
| 719 |
+
raise ValueError(f'Unknown interface: {interface}')
|
| 720 |
+
|
| 721 |
+
if target == 'E_i':
|
| 722 |
+
term_dict = {}
|
| 723 |
+
onsite_term_dict = {}
|
| 724 |
+
for graph_key in graph_key_list:
|
| 725 |
+
term_dict[graph_key] = torch.full([numbers.shape[0], 1], np.nan, dtype=default_dtype_torch)
|
| 726 |
+
for index_atom in range(numbers.shape[0]):
|
| 727 |
+
assert index_atom in read_terms_dict[graph_key_list[0]]
|
| 728 |
+
for graph_key in graph_key_list:
|
| 729 |
+
term_dict[graph_key][index_atom] = read_terms_dict[graph_key][index_atom]
|
| 730 |
+
subgraph = None
|
| 731 |
+
else:
|
| 732 |
+
if interface == 'h5_rc_only' or interface == 'npz_rc_only':
|
| 733 |
+
local_rotation = []
|
| 734 |
+
else:
|
| 735 |
+
term_dict = {}
|
| 736 |
+
onsite_term_dict = {}
|
| 737 |
+
if target == 'E_ij':
|
| 738 |
+
for graph_key in graph_key_list:
|
| 739 |
+
term_dict[graph_key] = torch.full([edge_fea.shape[0], 1], np.nan, dtype=default_dtype_torch)
|
| 740 |
+
local_rotation = []
|
| 741 |
+
if separate_onsite is True:
|
| 742 |
+
for graph_key in graph_key_list:
|
| 743 |
+
onsite_term_dict['onsite_' + graph_key] = torch.full([numbers.shape[0], 1], np.nan, dtype=default_dtype_torch)
|
| 744 |
+
else:
|
| 745 |
+
term_mask = torch.zeros(edge_fea.shape[0], dtype=torch.bool)
|
| 746 |
+
for graph_key in graph_key_list:
|
| 747 |
+
if spinful:
|
| 748 |
+
term_dict[graph_key] = torch.full([edge_fea.shape[0], max_num_orbital, max_num_orbital, 8],
|
| 749 |
+
np.nan, dtype=default_dtype_torch)
|
| 750 |
+
else:
|
| 751 |
+
if target == 'phiVdphi':
|
| 752 |
+
term_dict[graph_key] = torch.full([edge_fea.shape[0], max_num_orbital, max_num_orbital, 3],
|
| 753 |
+
np.nan, dtype=default_dtype_torch)
|
| 754 |
+
else:
|
| 755 |
+
term_dict[graph_key] = torch.full([edge_fea.shape[0], max_num_orbital, max_num_orbital],
|
| 756 |
+
np.nan, dtype=default_dtype_torch)
|
| 757 |
+
local_rotation = []
|
| 758 |
+
if separate_onsite is True:
|
| 759 |
+
for graph_key in graph_key_list:
|
| 760 |
+
if spinful:
|
| 761 |
+
onsite_term_dict['onsite_' + graph_key] = torch.full(
|
| 762 |
+
[numbers.shape[0], max_num_orbital, max_num_orbital, 8],
|
| 763 |
+
np.nan, dtype=default_dtype_torch)
|
| 764 |
+
else:
|
| 765 |
+
if target == 'phiVdphi':
|
| 766 |
+
onsite_term_dict['onsite_' + graph_key] = torch.full(
|
| 767 |
+
[numbers.shape[0], max_num_orbital, max_num_orbital, 3],
|
| 768 |
+
np.nan, dtype=default_dtype_torch)
|
| 769 |
+
else:
|
| 770 |
+
onsite_term_dict['onsite_' + graph_key] = torch.full(
|
| 771 |
+
[numbers.shape[0], max_num_orbital, max_num_orbital],
|
| 772 |
+
np.nan, dtype=default_dtype_torch)
|
| 773 |
+
|
| 774 |
+
inv_lattice = torch.inverse(lattice).type(default_dtype_torch)
|
| 775 |
+
for index_edge in range(edge_fea.shape[0]):
|
| 776 |
+
# h_{i0, jR} i and j is 0-based index
|
| 777 |
+
R = torch.round(edge_fea[index_edge, 4:7].cpu() @ inv_lattice - edge_fea[index_edge, 7:10].cpu() @ inv_lattice).int().tolist()
|
| 778 |
+
i, j = edge_idx[:, index_edge]
|
| 779 |
+
|
| 780 |
+
key_term = (*R, i.item(), j.item())
|
| 781 |
+
if interface == 'h5_rc_only' or interface == 'npz_rc_only':
|
| 782 |
+
local_rotation.append(local_rotation_dict[key_term])
|
| 783 |
+
else:
|
| 784 |
+
if key_term in read_terms_dict[graph_key_list[0]]:
|
| 785 |
+
for graph_key in graph_key_list:
|
| 786 |
+
if target == 'E_ij':
|
| 787 |
+
term_dict[graph_key][index_edge] = read_terms_dict[graph_key][key_term]
|
| 788 |
+
else:
|
| 789 |
+
term_mask[index_edge] = True
|
| 790 |
+
if spinful:
|
| 791 |
+
term_dict[graph_key][index_edge, :atom_num_orbital[i], :atom_num_orbital[j], :] = read_terms_dict[graph_key][key_term]
|
| 792 |
+
else:
|
| 793 |
+
term_dict[graph_key][index_edge, :atom_num_orbital[i], :atom_num_orbital[j]] = read_terms_dict[graph_key][key_term]
|
| 794 |
+
local_rotation.append(local_rotation_dict[key_term])
|
| 795 |
+
else:
|
| 796 |
+
raise NotImplementedError(
|
| 797 |
+
"Not yet have support for graph radius including hopping without calculation")
|
| 798 |
+
|
| 799 |
+
if separate_onsite is True and interface != 'h5_rc_only' and interface != 'npz_rc_only':
|
| 800 |
+
for index_atom in range(numbers.shape[0]):
|
| 801 |
+
key_term = (0, 0, 0, index_atom, index_atom)
|
| 802 |
+
assert key_term in read_terms_dict[graph_key_list[0]]
|
| 803 |
+
for graph_key in graph_key_list:
|
| 804 |
+
if target == 'E_ij':
|
| 805 |
+
onsite_term_dict['onsite_' + graph_key][index_atom] = read_terms_dict[graph_key][key_term]
|
| 806 |
+
else:
|
| 807 |
+
if spinful:
|
| 808 |
+
onsite_term_dict['onsite_' + graph_key][index_atom, :atom_num_orbital[i], :atom_num_orbital[j], :] = \
|
| 809 |
+
read_terms_dict[graph_key][key_term]
|
| 810 |
+
else:
|
| 811 |
+
onsite_term_dict['onsite_' + graph_key][index_atom, :atom_num_orbital[i], :atom_num_orbital[j]] = \
|
| 812 |
+
read_terms_dict[graph_key][key_term]
|
| 813 |
+
|
| 814 |
+
if if_lcmp_graph:
|
| 815 |
+
local_rotation = torch.stack(local_rotation, dim=0)
|
| 816 |
+
assert local_rotation.shape[0] == edge_fea.shape[0]
|
| 817 |
+
r_vec = edge_fea[:, 1:4] - edge_fea[:, 4:7]
|
| 818 |
+
r_vec = r_vec.unsqueeze(1)
|
| 819 |
+
if huge_structure is False:
|
| 820 |
+
r_vec = torch.matmul(r_vec[:, None, :, :], local_rotation[None, :, :, :].to(r_vec.device)).reshape(-1, 3)
|
| 821 |
+
if if_new_sp:
|
| 822 |
+
r_vec = torch.nn.functional.normalize(r_vec, dim=-1)
|
| 823 |
+
angular_expansion = _spherical_harmonics(num_l - 1, -r_vec[..., 2], r_vec[..., 0],
|
| 824 |
+
r_vec[..., 1])
|
| 825 |
+
angular_expansion.mul_(torch.cat([
|
| 826 |
+
(math.sqrt(2 * l + 1) / math.sqrt(4 * math.pi)) * torch.ones(2 * l + 1,
|
| 827 |
+
dtype=angular_expansion.dtype,
|
| 828 |
+
device=angular_expansion.device)
|
| 829 |
+
for l in range(num_l)
|
| 830 |
+
]))
|
| 831 |
+
angular_expansion = angular_expansion.reshape(edge_fea.shape[0], edge_fea.shape[0], -1)
|
| 832 |
+
else:
|
| 833 |
+
r_vec_sp = get_spherical_from_cartesian(r_vec)
|
| 834 |
+
sph_harm_func = SphericalHarmonics()
|
| 835 |
+
angular_expansion = []
|
| 836 |
+
for l in range(num_l):
|
| 837 |
+
angular_expansion.append(sph_harm_func.get(l, r_vec_sp[:, 0], r_vec_sp[:, 1]))
|
| 838 |
+
angular_expansion = torch.cat(angular_expansion, dim=-1).reshape(edge_fea.shape[0], edge_fea.shape[0], -1)
|
| 839 |
+
|
| 840 |
+
subgraph_atom_idx_list = []
|
| 841 |
+
subgraph_edge_idx_list = []
|
| 842 |
+
subgraph_edge_ang_list = []
|
| 843 |
+
subgraph_index = []
|
| 844 |
+
index_cursor = 0
|
| 845 |
+
|
| 846 |
+
for index in range(edge_fea.shape[0]):
|
| 847 |
+
# h_{i0, jR}
|
| 848 |
+
i, j = edge_idx[:, index]
|
| 849 |
+
subgraph_atom_idx = torch.stack([i.repeat(len(atom_idx_connect[i])), atom_idx_connect[i]]).T
|
| 850 |
+
subgraph_edge_idx = torch.LongTensor(edge_idx_connect[i])
|
| 851 |
+
if huge_structure:
|
| 852 |
+
r_vec_tmp = torch.matmul(r_vec[subgraph_edge_idx, :, :], local_rotation[index, :, :].to(r_vec.device)).reshape(-1, 3)
|
| 853 |
+
if if_new_sp:
|
| 854 |
+
r_vec_tmp = torch.nn.functional.normalize(r_vec_tmp, dim=-1)
|
| 855 |
+
subgraph_edge_ang = _spherical_harmonics(num_l - 1, -r_vec_tmp[..., 2], r_vec_tmp[..., 0], r_vec_tmp[..., 1])
|
| 856 |
+
subgraph_edge_ang.mul_(torch.cat([
|
| 857 |
+
(math.sqrt(2 * l + 1) / math.sqrt(4 * math.pi)) * torch.ones(2 * l + 1,
|
| 858 |
+
dtype=subgraph_edge_ang.dtype,
|
| 859 |
+
device=subgraph_edge_ang.device)
|
| 860 |
+
for l in range(num_l)
|
| 861 |
+
]))
|
| 862 |
+
else:
|
| 863 |
+
r_vec_sp = get_spherical_from_cartesian(r_vec_tmp)
|
| 864 |
+
sph_harm_func = SphericalHarmonics()
|
| 865 |
+
angular_expansion = []
|
| 866 |
+
for l in range(num_l):
|
| 867 |
+
angular_expansion.append(sph_harm_func.get(l, r_vec_sp[:, 0], r_vec_sp[:, 1]))
|
| 868 |
+
subgraph_edge_ang = torch.cat(angular_expansion, dim=-1).reshape(-1, num_l ** 2)
|
| 869 |
+
else:
|
| 870 |
+
subgraph_edge_ang = angular_expansion[subgraph_edge_idx, index, :]
|
| 871 |
+
|
| 872 |
+
subgraph_atom_idx_list.append(subgraph_atom_idx)
|
| 873 |
+
subgraph_edge_idx_list.append(subgraph_edge_idx)
|
| 874 |
+
subgraph_edge_ang_list.append(subgraph_edge_ang)
|
| 875 |
+
subgraph_index += [index_cursor] * len(atom_idx_connect[i])
|
| 876 |
+
index_cursor += 1
|
| 877 |
+
|
| 878 |
+
subgraph_atom_idx = torch.stack([j.repeat(len(atom_idx_connect[j])), atom_idx_connect[j]]).T
|
| 879 |
+
subgraph_edge_idx = torch.LongTensor(edge_idx_connect[j])
|
| 880 |
+
if huge_structure:
|
| 881 |
+
r_vec_tmp = torch.matmul(r_vec[subgraph_edge_idx, :, :], local_rotation[index, :, :].to(r_vec.device)).reshape(-1, 3)
|
| 882 |
+
if if_new_sp:
|
| 883 |
+
r_vec_tmp = torch.nn.functional.normalize(r_vec_tmp, dim=-1)
|
| 884 |
+
subgraph_edge_ang = _spherical_harmonics(num_l - 1, -r_vec_tmp[..., 2], r_vec_tmp[..., 0], r_vec_tmp[..., 1])
|
| 885 |
+
subgraph_edge_ang.mul_(torch.cat([
|
| 886 |
+
(math.sqrt(2 * l + 1) / math.sqrt(4 * math.pi)) * torch.ones(2 * l + 1,
|
| 887 |
+
dtype=subgraph_edge_ang.dtype,
|
| 888 |
+
device=subgraph_edge_ang.device)
|
| 889 |
+
for l in range(num_l)
|
| 890 |
+
]))
|
| 891 |
+
else:
|
| 892 |
+
r_vec_sp = get_spherical_from_cartesian(r_vec_tmp)
|
| 893 |
+
sph_harm_func = SphericalHarmonics()
|
| 894 |
+
angular_expansion = []
|
| 895 |
+
for l in range(num_l):
|
| 896 |
+
angular_expansion.append(sph_harm_func.get(l, r_vec_sp[:, 0], r_vec_sp[:, 1]))
|
| 897 |
+
subgraph_edge_ang = torch.cat(angular_expansion, dim=-1).reshape(-1, num_l ** 2)
|
| 898 |
+
else:
|
| 899 |
+
subgraph_edge_ang = angular_expansion[subgraph_edge_idx, index, :]
|
| 900 |
+
subgraph_atom_idx_list.append(subgraph_atom_idx)
|
| 901 |
+
subgraph_edge_idx_list.append(subgraph_edge_idx)
|
| 902 |
+
subgraph_edge_ang_list.append(subgraph_edge_ang)
|
| 903 |
+
subgraph_index += [index_cursor] * len(atom_idx_connect[j])
|
| 904 |
+
index_cursor += 1
|
| 905 |
+
subgraph = {"subgraph_atom_idx":torch.cat(subgraph_atom_idx_list, dim=0),
|
| 906 |
+
"subgraph_edge_idx":torch.cat(subgraph_edge_idx_list, dim=0),
|
| 907 |
+
"subgraph_edge_ang":torch.cat(subgraph_edge_ang_list, dim=0),
|
| 908 |
+
"subgraph_index":torch.LongTensor(subgraph_index)}
|
| 909 |
+
else:
|
| 910 |
+
subgraph = None
|
| 911 |
+
|
| 912 |
+
if interface == 'h5_rc_only' or interface == 'npz_rc_only':
|
| 913 |
+
data = Data(x=numbers, edge_index=edge_idx, edge_attr=edge_fea, stru_id=stru_id, term_mask=None,
|
| 914 |
+
term_real=None, onsite_term_real=None,
|
| 915 |
+
atom_num_orbital=torch.tensor(atom_num_orbital),
|
| 916 |
+
subgraph_dict=subgraph,
|
| 917 |
+
**kwargs)
|
| 918 |
+
else:
|
| 919 |
+
if target == 'E_ij' or target == 'E_i':
|
| 920 |
+
data = Data(x=numbers, edge_index=edge_idx, edge_attr=edge_fea, stru_id=stru_id,
|
| 921 |
+
**term_dict, **onsite_term_dict,
|
| 922 |
+
subgraph_dict=subgraph,
|
| 923 |
+
spinful=False,
|
| 924 |
+
**kwargs)
|
| 925 |
+
else:
|
| 926 |
+
data = Data(x=numbers, edge_index=edge_idx, edge_attr=edge_fea, stru_id=stru_id, term_mask=term_mask,
|
| 927 |
+
**term_dict, **onsite_term_dict,
|
| 928 |
+
atom_num_orbital=torch.tensor(atom_num_orbital),
|
| 929 |
+
subgraph_dict=subgraph,
|
| 930 |
+
spinful=spinful,
|
| 931 |
+
**kwargs)
|
| 932 |
+
else:
|
| 933 |
+
data = Data(x=numbers, edge_index=edge_idx, edge_attr=edge_fea, stru_id=stru_id, **kwargs)
|
| 934 |
+
return data
|
3_epc/displacements/group_8/reconstruction/aohamiltonian/pred_ham_std/src/deeph/kernel.py
ADDED
|
@@ -0,0 +1,844 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
import os
|
| 3 |
+
from inspect import signature
|
| 4 |
+
import time
|
| 5 |
+
import csv
|
| 6 |
+
import sys
|
| 7 |
+
import shutil
|
| 8 |
+
import random
|
| 9 |
+
import warnings
|
| 10 |
+
from math import sqrt
|
| 11 |
+
from itertools import islice
|
| 12 |
+
from configparser import ConfigParser
|
| 13 |
+
|
| 14 |
+
import torch
|
| 15 |
+
import torch.optim as optim
|
| 16 |
+
from torch import package
|
| 17 |
+
from torch.nn import MSELoss
|
| 18 |
+
from torch.optim.lr_scheduler import MultiStepLR, ReduceLROnPlateau, CyclicLR
|
| 19 |
+
from torch.utils.data import SubsetRandomSampler, DataLoader
|
| 20 |
+
from torch.nn.utils import clip_grad_norm_
|
| 21 |
+
from torch.utils.tensorboard import SummaryWriter
|
| 22 |
+
from torch_scatter import scatter_add
|
| 23 |
+
import numpy as np
|
| 24 |
+
from psutil import cpu_count
|
| 25 |
+
|
| 26 |
+
from .data import HData
|
| 27 |
+
from .graph import Collater
|
| 28 |
+
from .utils import Logger, save_model, LossRecord, MaskMSELoss, Transform
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
class DeepHKernel:
|
| 32 |
+
def __init__(self, config: ConfigParser):
|
| 33 |
+
self.config = config
|
| 34 |
+
|
| 35 |
+
# basic config
|
| 36 |
+
if config.getboolean('basic', 'save_to_time_folder'):
|
| 37 |
+
config.set('basic', 'save_dir',
|
| 38 |
+
os.path.join(config.get('basic', 'save_dir'),
|
| 39 |
+
str(time.strftime('%Y-%m-%d_%H-%M-%S', time.localtime(time.time())))))
|
| 40 |
+
assert not os.path.exists(config.get('basic', 'save_dir'))
|
| 41 |
+
os.makedirs(config.get('basic', 'save_dir'), exist_ok=True)
|
| 42 |
+
|
| 43 |
+
sys.stdout = Logger(os.path.join(config.get('basic', 'save_dir'), "result.txt"))
|
| 44 |
+
sys.stderr = Logger(os.path.join(config.get('basic', 'save_dir'), "stderr.txt"))
|
| 45 |
+
self.if_tensorboard = config.getboolean('basic', 'tb_writer')
|
| 46 |
+
if self.if_tensorboard:
|
| 47 |
+
self.tb_writer = SummaryWriter(os.path.join(config.get('basic', 'save_dir'), "tensorboard"))
|
| 48 |
+
src_dir = os.path.join(config.get('basic', 'save_dir'), "src")
|
| 49 |
+
os.makedirs(src_dir, exist_ok=True)
|
| 50 |
+
try:
|
| 51 |
+
shutil.copytree(os.path.dirname(__file__), os.path.join(src_dir, 'deeph'))
|
| 52 |
+
except:
|
| 53 |
+
warnings.warn("Unable to copy scripts")
|
| 54 |
+
if not config.getboolean('basic', 'disable_cuda'):
|
| 55 |
+
self.device = torch.device(config.get('basic', 'device') if torch.cuda.is_available() else 'cpu')
|
| 56 |
+
else:
|
| 57 |
+
self.device = torch.device('cpu')
|
| 58 |
+
config.set('basic', 'device', str(self.device))
|
| 59 |
+
if config.get('hyperparameter', 'dtype') == 'float32':
|
| 60 |
+
default_dtype_torch = torch.float32
|
| 61 |
+
elif config.get('hyperparameter', 'dtype') == 'float16':
|
| 62 |
+
default_dtype_torch = torch.float16
|
| 63 |
+
elif config.get('hyperparameter', 'dtype') == 'float64':
|
| 64 |
+
default_dtype_torch = torch.float64
|
| 65 |
+
else:
|
| 66 |
+
raise ValueError('Unknown dtype: {}'.format(config.get('hyperparameter', 'dtype')))
|
| 67 |
+
np.seterr(all='raise')
|
| 68 |
+
np.seterr(under='warn')
|
| 69 |
+
np.set_printoptions(precision=8, linewidth=160)
|
| 70 |
+
torch.set_default_dtype(default_dtype_torch)
|
| 71 |
+
torch.set_printoptions(precision=8, linewidth=160, threshold=np.inf)
|
| 72 |
+
np.random.seed(config.getint('basic', 'seed'))
|
| 73 |
+
torch.manual_seed(config.getint('basic', 'seed'))
|
| 74 |
+
torch.cuda.manual_seed_all(config.getint('basic', 'seed'))
|
| 75 |
+
random.seed(config.getint('basic', 'seed'))
|
| 76 |
+
torch.backends.cudnn.benchmark = False
|
| 77 |
+
torch.backends.cudnn.deterministic = True
|
| 78 |
+
torch.cuda.empty_cache()
|
| 79 |
+
|
| 80 |
+
if config.getint('basic', 'num_threads', fallback=-1) == -1:
|
| 81 |
+
if torch.cuda.device_count() == 0:
|
| 82 |
+
torch.set_num_threads(cpu_count(logical=False))
|
| 83 |
+
else:
|
| 84 |
+
torch.set_num_threads(cpu_count(logical=False) // torch.cuda.device_count())
|
| 85 |
+
else:
|
| 86 |
+
torch.set_num_threads(config.getint('basic', 'num_threads'))
|
| 87 |
+
|
| 88 |
+
print('====== CONFIG ======')
|
| 89 |
+
for section_k, section_v in islice(config.items(), 1, None):
|
| 90 |
+
print(f'[{section_k}]')
|
| 91 |
+
for k, v in section_v.items():
|
| 92 |
+
print(f'{k}={v}')
|
| 93 |
+
print('')
|
| 94 |
+
config.write(open(os.path.join(config.get('basic', 'save_dir'), 'config.ini'), "w"))
|
| 95 |
+
|
| 96 |
+
self.if_lcmp = self.config.getboolean('network', 'if_lcmp', fallback=True)
|
| 97 |
+
self.if_lcmp_graph = self.config.getboolean('graph', 'if_lcmp_graph', fallback=True)
|
| 98 |
+
self.new_sp = self.config.getboolean('graph', 'new_sp', fallback=False)
|
| 99 |
+
self.separate_onsite = self.config.getboolean('graph', 'separate_onsite', fallback=False)
|
| 100 |
+
if self.if_lcmp == True:
|
| 101 |
+
assert self.if_lcmp_graph == True
|
| 102 |
+
self.target = self.config.get('basic', 'target')
|
| 103 |
+
if self.target == 'O_ij':
|
| 104 |
+
self.O_component = config['basic']['O_component']
|
| 105 |
+
if self.target != 'E_ij' and self.target != 'E_i':
|
| 106 |
+
self.orbital = json.loads(config.get('basic', 'orbital'))
|
| 107 |
+
self.num_orbital = len(self.orbital)
|
| 108 |
+
else:
|
| 109 |
+
self.energy_component = config['basic']['energy_component']
|
| 110 |
+
# early_stopping
|
| 111 |
+
self.early_stopping_loss_epoch = json.loads(self.config.get('train', 'early_stopping_loss_epoch'))
|
| 112 |
+
|
| 113 |
+
def build_model(self, model_pack_dir: str = None, old_version=None):
|
| 114 |
+
if model_pack_dir is not None:
|
| 115 |
+
assert old_version is not None
|
| 116 |
+
if old_version is True:
|
| 117 |
+
print(f'import HGNN from {model_pack_dir}')
|
| 118 |
+
sys.path.append(model_pack_dir)
|
| 119 |
+
from src.deeph import HGNN
|
| 120 |
+
else:
|
| 121 |
+
imp = package.PackageImporter(os.path.join(model_pack_dir, 'best_model.pt'))
|
| 122 |
+
checkpoint = imp.load_pickle('checkpoint', 'model.pkl', map_location=self.device)
|
| 123 |
+
self.model = checkpoint['model']
|
| 124 |
+
self.model.to(self.device)
|
| 125 |
+
self.index_to_Z = checkpoint["index_to_Z"]
|
| 126 |
+
self.Z_to_index = checkpoint["Z_to_index"]
|
| 127 |
+
self.spinful = checkpoint["spinful"]
|
| 128 |
+
print("=> load best checkpoint (epoch {})".format(checkpoint['epoch']))
|
| 129 |
+
print(f"=> Atomic types: {self.index_to_Z.tolist()}, "
|
| 130 |
+
f"spinful: {self.spinful}, the number of atomic types: {len(self.index_to_Z)}.")
|
| 131 |
+
if self.target != 'E_ij':
|
| 132 |
+
if self.spinful:
|
| 133 |
+
self.out_fea_len = self.num_orbital * 8
|
| 134 |
+
else:
|
| 135 |
+
self.out_fea_len = self.num_orbital
|
| 136 |
+
else:
|
| 137 |
+
if self.energy_component == 'both':
|
| 138 |
+
self.out_fea_len = 2
|
| 139 |
+
elif self.energy_component in ['xc', 'delta_ee', 'summation']:
|
| 140 |
+
self.out_fea_len = 1
|
| 141 |
+
else:
|
| 142 |
+
raise ValueError('Unknown energy_component: {}'.format(self.energy_component))
|
| 143 |
+
return checkpoint
|
| 144 |
+
else:
|
| 145 |
+
from .model import HGNN
|
| 146 |
+
|
| 147 |
+
if self.spinful:
|
| 148 |
+
if self.target == 'phiVdphi':
|
| 149 |
+
raise NotImplementedError("Not yet have support for phiVdphi")
|
| 150 |
+
else:
|
| 151 |
+
self.out_fea_len = self.num_orbital * 8
|
| 152 |
+
else:
|
| 153 |
+
if self.target == 'phiVdphi':
|
| 154 |
+
self.out_fea_len = self.num_orbital * 3
|
| 155 |
+
else:
|
| 156 |
+
self.out_fea_len = self.num_orbital
|
| 157 |
+
|
| 158 |
+
print(f'Output features length of single edge: {self.out_fea_len}')
|
| 159 |
+
model_kwargs = dict(
|
| 160 |
+
n_elements=self.num_species,
|
| 161 |
+
num_species=self.num_species,
|
| 162 |
+
in_atom_fea_len=self.config.getint('network', 'atom_fea_len'),
|
| 163 |
+
in_vfeats=self.config.getint('network', 'atom_fea_len'),
|
| 164 |
+
in_edge_fea_len=self.config.getint('network', 'edge_fea_len'),
|
| 165 |
+
in_efeats=self.config.getint('network', 'edge_fea_len'),
|
| 166 |
+
out_edge_fea_len=self.out_fea_len,
|
| 167 |
+
out_efeats=self.out_fea_len,
|
| 168 |
+
num_orbital=self.out_fea_len,
|
| 169 |
+
distance_expansion=self.config.get('network', 'distance_expansion'),
|
| 170 |
+
gauss_stop=self.config.getfloat('network', 'gauss_stop'),
|
| 171 |
+
cutoff=self.config.getfloat('network', 'gauss_stop'),
|
| 172 |
+
if_exp=self.config.getboolean('network', 'if_exp'),
|
| 173 |
+
if_MultipleLinear=self.config.getboolean('network', 'if_MultipleLinear'),
|
| 174 |
+
if_edge_update=self.config.getboolean('network', 'if_edge_update'),
|
| 175 |
+
if_lcmp=self.if_lcmp,
|
| 176 |
+
normalization=self.config.get('network', 'normalization'),
|
| 177 |
+
atom_update_net=self.config.get('network', 'atom_update_net', fallback='CGConv'),
|
| 178 |
+
separate_onsite=self.separate_onsite,
|
| 179 |
+
num_l=self.config.getint('network', 'num_l'),
|
| 180 |
+
trainable_gaussians=self.config.getboolean('network', 'trainable_gaussians', fallback=False),
|
| 181 |
+
type_affine=self.config.getboolean('network', 'type_affine', fallback=False),
|
| 182 |
+
if_fc_out=False,
|
| 183 |
+
)
|
| 184 |
+
parameter_list = list(signature(HGNN.__init__).parameters.keys())
|
| 185 |
+
current_parameter_list = list(model_kwargs.keys())
|
| 186 |
+
for k in current_parameter_list:
|
| 187 |
+
if k not in parameter_list:
|
| 188 |
+
model_kwargs.pop(k)
|
| 189 |
+
if 'num_elements' in parameter_list:
|
| 190 |
+
model_kwargs['num_elements'] = self.config.getint('basic', 'max_element') + 1
|
| 191 |
+
self.model = HGNN(
|
| 192 |
+
**model_kwargs
|
| 193 |
+
)
|
| 194 |
+
|
| 195 |
+
model_parameters = filter(lambda p: p.requires_grad, self.model.parameters())
|
| 196 |
+
params = sum([np.prod(p.size()) for p in model_parameters])
|
| 197 |
+
print("The model you built has: %d parameters" % params)
|
| 198 |
+
self.model.to(self.device)
|
| 199 |
+
self.load_pretrained()
|
| 200 |
+
|
| 201 |
+
def set_train(self):
|
| 202 |
+
self.criterion_name = self.config.get('hyperparameter', 'criterion', fallback='MaskMSELoss')
|
| 203 |
+
if self.target == "E_i":
|
| 204 |
+
self.criterion = MSELoss()
|
| 205 |
+
elif self.target == "E_ij":
|
| 206 |
+
self.criterion = MSELoss()
|
| 207 |
+
self.retain_edge_fea = self.config.getboolean('hyperparameter', 'retain_edge_fea')
|
| 208 |
+
self.lambda_Eij = self.config.getfloat('hyperparameter', 'lambda_Eij')
|
| 209 |
+
self.lambda_Ei = self.config.getfloat('hyperparameter', 'lambda_Ei')
|
| 210 |
+
self.lambda_Etot = self.config.getfloat('hyperparameter', 'lambda_Etot')
|
| 211 |
+
if self.retain_edge_fea is False:
|
| 212 |
+
assert self.lambda_Eij == 0.0
|
| 213 |
+
else:
|
| 214 |
+
if self.criterion_name == 'MaskMSELoss':
|
| 215 |
+
self.criterion = MaskMSELoss()
|
| 216 |
+
else:
|
| 217 |
+
raise ValueError(f'Unknown criterion: {self.criterion_name}')
|
| 218 |
+
|
| 219 |
+
learning_rate = self.config.getfloat('hyperparameter', 'learning_rate')
|
| 220 |
+
momentum = self.config.getfloat('hyperparameter', 'momentum')
|
| 221 |
+
weight_decay = self.config.getfloat('hyperparameter', 'weight_decay')
|
| 222 |
+
|
| 223 |
+
model_parameters = filter(lambda p: p.requires_grad, self.model.parameters())
|
| 224 |
+
if self.config.get('hyperparameter', 'optimizer') == 'sgd':
|
| 225 |
+
self.optimizer = optim.SGD(model_parameters, lr=learning_rate, weight_decay=weight_decay)
|
| 226 |
+
elif self.config.get('hyperparameter', 'optimizer') == 'sgdm':
|
| 227 |
+
self.optimizer = optim.SGD(model_parameters, lr=learning_rate, momentum=momentum, weight_decay=weight_decay)
|
| 228 |
+
elif self.config.get('hyperparameter', 'optimizer') == 'adam':
|
| 229 |
+
self.optimizer = optim.Adam(model_parameters, lr=learning_rate, betas=(0.9, 0.999))
|
| 230 |
+
elif self.config.get('hyperparameter', 'optimizer') == 'adamW':
|
| 231 |
+
self.optimizer = optim.AdamW(model_parameters, lr=learning_rate, betas=(0.9, 0.999))
|
| 232 |
+
elif self.config.get('hyperparameter', 'optimizer') == 'adagrad':
|
| 233 |
+
self.optimizer = optim.Adagrad(model_parameters, lr=learning_rate)
|
| 234 |
+
elif self.config.get('hyperparameter', 'optimizer') == 'RMSprop':
|
| 235 |
+
self.optimizer = optim.RMSprop(model_parameters, lr=learning_rate)
|
| 236 |
+
elif self.config.get('hyperparameter', 'optimizer') == 'lbfgs':
|
| 237 |
+
self.optimizer = optim.LBFGS(model_parameters, lr=0.1)
|
| 238 |
+
else:
|
| 239 |
+
raise ValueError(f'Unknown optimizer: {self.optimizer}')
|
| 240 |
+
|
| 241 |
+
if self.config.get('hyperparameter', 'lr_scheduler') == '':
|
| 242 |
+
pass
|
| 243 |
+
elif self.config.get('hyperparameter', 'lr_scheduler') == 'MultiStepLR':
|
| 244 |
+
lr_milestones = json.loads(self.config.get('hyperparameter', 'lr_milestones'))
|
| 245 |
+
self.scheduler = MultiStepLR(self.optimizer, milestones=lr_milestones, gamma=0.2)
|
| 246 |
+
elif self.config.get('hyperparameter', 'lr_scheduler') == 'ReduceLROnPlateau':
|
| 247 |
+
self.scheduler = ReduceLROnPlateau(self.optimizer, mode='min', factor=0.2, patience=10,
|
| 248 |
+
verbose=True, threshold=1e-4, threshold_mode='rel', min_lr=0)
|
| 249 |
+
elif self.config.get('hyperparameter', 'lr_scheduler') == 'CyclicLR':
|
| 250 |
+
self.scheduler = CyclicLR(self.optimizer, base_lr=learning_rate * 0.1, max_lr=learning_rate,
|
| 251 |
+
mode='triangular', step_size_up=50, step_size_down=50, cycle_momentum=False)
|
| 252 |
+
else:
|
| 253 |
+
raise ValueError('Unknown lr_scheduler: {}'.format(self.config.getfloat('hyperparameter', 'lr_scheduler')))
|
| 254 |
+
self.load_resume()
|
| 255 |
+
|
| 256 |
+
def load_pretrained(self):
|
| 257 |
+
pretrained = self.config.get('train', 'pretrained')
|
| 258 |
+
if pretrained:
|
| 259 |
+
if os.path.isfile(pretrained):
|
| 260 |
+
checkpoint = torch.load(pretrained, map_location=self.device)
|
| 261 |
+
pretrained_dict = checkpoint['state_dict']
|
| 262 |
+
model_dict = self.model.state_dict()
|
| 263 |
+
|
| 264 |
+
transfer_dict = {}
|
| 265 |
+
for k, v in pretrained_dict.items():
|
| 266 |
+
if v.shape == model_dict[k].shape:
|
| 267 |
+
transfer_dict[k] = v
|
| 268 |
+
print('Use pretrained parameters:', k)
|
| 269 |
+
|
| 270 |
+
model_dict.update(transfer_dict)
|
| 271 |
+
self.model.load_state_dict(model_dict)
|
| 272 |
+
print(f'=> loaded pretrained model at "{pretrained}" (epoch {checkpoint["epoch"]})')
|
| 273 |
+
else:
|
| 274 |
+
print(f'=> no checkpoint found at "{pretrained}"')
|
| 275 |
+
|
| 276 |
+
def load_resume(self):
|
| 277 |
+
resume = self.config.get('train', 'resume')
|
| 278 |
+
if resume:
|
| 279 |
+
if os.path.isfile(resume):
|
| 280 |
+
checkpoint = torch.load(resume, map_location=self.device)
|
| 281 |
+
self.model.load_state_dict(checkpoint['state_dict'])
|
| 282 |
+
self.optimizer.load_state_dict(checkpoint['optimizer_state_dict'])
|
| 283 |
+
print(f'=> loaded model at "{resume}" (epoch {checkpoint["epoch"]})')
|
| 284 |
+
else:
|
| 285 |
+
print(f'=> no checkpoint found at "{resume}"')
|
| 286 |
+
|
| 287 |
+
def get_dataset(self, only_get_graph=False):
|
| 288 |
+
dataset = HData(
|
| 289 |
+
raw_data_dir=self.config.get('basic', 'raw_dir'),
|
| 290 |
+
graph_dir=self.config.get('basic', 'graph_dir'),
|
| 291 |
+
interface=self.config.get('basic', 'interface'),
|
| 292 |
+
target=self.target,
|
| 293 |
+
dataset_name=self.config.get('basic', 'dataset_name'),
|
| 294 |
+
multiprocessing=self.config.getint('basic', 'multiprocessing', fallback=0),
|
| 295 |
+
radius=self.config.getfloat('graph', 'radius'),
|
| 296 |
+
max_num_nbr=self.config.getint('graph', 'max_num_nbr'),
|
| 297 |
+
num_l=self.config.getint('network', 'num_l'),
|
| 298 |
+
max_element=self.config.getint('basic', 'max_element'),
|
| 299 |
+
create_from_DFT=self.config.getboolean('graph', 'create_from_DFT', fallback=True),
|
| 300 |
+
if_lcmp_graph=self.if_lcmp_graph,
|
| 301 |
+
separate_onsite=self.separate_onsite,
|
| 302 |
+
new_sp=self.new_sp,
|
| 303 |
+
default_dtype_torch=torch.get_default_dtype(),
|
| 304 |
+
)
|
| 305 |
+
if only_get_graph:
|
| 306 |
+
return None, None, None, None
|
| 307 |
+
self.spinful = dataset.info["spinful"]
|
| 308 |
+
self.index_to_Z = dataset.info["index_to_Z"]
|
| 309 |
+
self.Z_to_index = dataset.info["Z_to_index"]
|
| 310 |
+
self.num_species = len(dataset.info["index_to_Z"])
|
| 311 |
+
if self.target != 'E_ij' and self.target != 'E_i':
|
| 312 |
+
dataset = self.make_mask(dataset)
|
| 313 |
+
|
| 314 |
+
dataset_size = len(dataset)
|
| 315 |
+
train_size = int(self.config.getfloat('train', 'train_ratio') * dataset_size)
|
| 316 |
+
val_size = int(self.config.getfloat('train', 'val_ratio') * dataset_size)
|
| 317 |
+
test_size = int(self.config.getfloat('train', 'test_ratio') * dataset_size)
|
| 318 |
+
assert train_size + val_size + test_size <= dataset_size
|
| 319 |
+
|
| 320 |
+
indices = list(range(dataset_size))
|
| 321 |
+
np.random.shuffle(indices)
|
| 322 |
+
print(f'number of train set: {len(indices[:train_size])}')
|
| 323 |
+
print(f'number of val set: {len(indices[train_size:train_size + val_size])}')
|
| 324 |
+
print(f'number of test set: {len(indices[train_size + val_size:train_size + val_size + test_size])}')
|
| 325 |
+
train_sampler = SubsetRandomSampler(indices[:train_size])
|
| 326 |
+
val_sampler = SubsetRandomSampler(indices[train_size:train_size + val_size])
|
| 327 |
+
test_sampler = SubsetRandomSampler(indices[train_size + val_size:train_size + val_size + test_size])
|
| 328 |
+
train_loader = DataLoader(dataset, batch_size=self.config.getint('hyperparameter', 'batch_size'),
|
| 329 |
+
shuffle=False, sampler=train_sampler,
|
| 330 |
+
collate_fn=Collater(self.if_lcmp))
|
| 331 |
+
val_loader = DataLoader(dataset, batch_size=self.config.getint('hyperparameter', 'batch_size'),
|
| 332 |
+
shuffle=False, sampler=val_sampler,
|
| 333 |
+
collate_fn=Collater(self.if_lcmp))
|
| 334 |
+
test_loader = DataLoader(dataset, batch_size=self.config.getint('hyperparameter', 'batch_size'),
|
| 335 |
+
shuffle=False, sampler=test_sampler,
|
| 336 |
+
collate_fn=Collater(self.if_lcmp))
|
| 337 |
+
|
| 338 |
+
if self.config.getboolean('basic', 'statistics'):
|
| 339 |
+
sample_label = torch.cat([dataset[i].label for i in range(len(dataset))])
|
| 340 |
+
sample_mask = torch.cat([dataset[i].mask for i in range(len(dataset))])
|
| 341 |
+
mean_value = abs(sample_label).sum(dim=0) / sample_mask.sum(dim=0)
|
| 342 |
+
import matplotlib.pyplot as plt
|
| 343 |
+
len_matrix = int(sqrt(self.out_fea_len))
|
| 344 |
+
if len_matrix ** 2 != self.out_fea_len:
|
| 345 |
+
raise ValueError
|
| 346 |
+
mean_value = mean_value.reshape(len_matrix, len_matrix)
|
| 347 |
+
im = plt.imshow(mean_value, cmap='Blues')
|
| 348 |
+
plt.colorbar(im)
|
| 349 |
+
plt.xticks(range(len_matrix), range(len_matrix))
|
| 350 |
+
plt.yticks(range(len_matrix), range(len_matrix))
|
| 351 |
+
plt.xlabel(r'Orbital $\beta$')
|
| 352 |
+
plt.ylabel(r'Orbital $\alpha$')
|
| 353 |
+
plt.title(r'Mean of abs($H^\prime_{i\alpha, j\beta}$)')
|
| 354 |
+
plt.tight_layout()
|
| 355 |
+
plt.savefig(os.path.join(self.config.get('basic', 'save_dir'), 'mean.png'), dpi=800)
|
| 356 |
+
np.savetxt(os.path.join(self.config.get('basic', 'save_dir'), 'mean.dat'), mean_value.numpy())
|
| 357 |
+
|
| 358 |
+
print(f"The statistical results are saved to {os.path.join(self.config.get('basic', 'save_dir'), 'mean.dat')}")
|
| 359 |
+
|
| 360 |
+
normalizer = self.config.getboolean('basic', 'normalizer')
|
| 361 |
+
boxcox = self.config.getboolean('basic', 'boxcox')
|
| 362 |
+
if normalizer == False and boxcox == False:
|
| 363 |
+
transform = Transform()
|
| 364 |
+
else:
|
| 365 |
+
sample_label = torch.cat([dataset[i].label for i in range(len(dataset))])
|
| 366 |
+
sample_mask = torch.cat([dataset[i].mask for i in range(len(dataset))])
|
| 367 |
+
transform = Transform(sample_label, mask=sample_mask, normalizer=normalizer, boxcox=boxcox)
|
| 368 |
+
print(transform.state_dict())
|
| 369 |
+
|
| 370 |
+
return train_loader, val_loader, test_loader, transform
|
| 371 |
+
|
| 372 |
+
def make_mask(self, dataset):
|
| 373 |
+
dataset_mask = []
|
| 374 |
+
for data in dataset:
|
| 375 |
+
if self.target == 'hamiltonian' or self.target == 'phiVdphi' or self.target == 'density_matrix':
|
| 376 |
+
Oij_value = data.term_real
|
| 377 |
+
if data.term_real is not None:
|
| 378 |
+
if_only_rc = False
|
| 379 |
+
else:
|
| 380 |
+
if_only_rc = True
|
| 381 |
+
elif self.target == 'O_ij':
|
| 382 |
+
if self.O_component == 'H_minimum':
|
| 383 |
+
Oij_value = data.rvdee + data.rvxc
|
| 384 |
+
elif self.O_component == 'H_minimum_withNA':
|
| 385 |
+
Oij_value = data.rvna + data.rvdee + data.rvxc
|
| 386 |
+
elif self.O_component == 'H':
|
| 387 |
+
Oij_value = data.rh
|
| 388 |
+
elif self.O_component == 'Rho':
|
| 389 |
+
Oij_value = data.rdm
|
| 390 |
+
else:
|
| 391 |
+
raise ValueError(f'Unknown O_component: {self.O_component}')
|
| 392 |
+
if_only_rc = False
|
| 393 |
+
else:
|
| 394 |
+
raise ValueError(f'Unknown target: {self.target}')
|
| 395 |
+
if if_only_rc == False:
|
| 396 |
+
if not torch.all(data.term_mask):
|
| 397 |
+
raise NotImplementedError("Not yet have support for graph radius including hopping without calculation")
|
| 398 |
+
|
| 399 |
+
if self.spinful:
|
| 400 |
+
if self.target == 'phiVdphi':
|
| 401 |
+
raise NotImplementedError("Not yet have support for phiVdphi")
|
| 402 |
+
else:
|
| 403 |
+
out_fea_len = self.num_orbital * 8
|
| 404 |
+
else:
|
| 405 |
+
if self.target == 'phiVdphi':
|
| 406 |
+
out_fea_len = self.num_orbital * 3
|
| 407 |
+
else:
|
| 408 |
+
out_fea_len = self.num_orbital
|
| 409 |
+
mask = torch.zeros(data.edge_attr.shape[0], out_fea_len, dtype=torch.int8)
|
| 410 |
+
label = torch.zeros(data.edge_attr.shape[0], out_fea_len, dtype=torch.get_default_dtype())
|
| 411 |
+
|
| 412 |
+
atomic_number_edge_i = self.index_to_Z[data.x[data.edge_index[0]]]
|
| 413 |
+
atomic_number_edge_j = self.index_to_Z[data.x[data.edge_index[1]]]
|
| 414 |
+
|
| 415 |
+
for index_out, orbital_dict in enumerate(self.orbital):
|
| 416 |
+
for N_M_str, a_b in orbital_dict.items():
|
| 417 |
+
# N_M, a_b means: H_{ia, jb} when the atomic number of atom i is N and the atomic number of atom j is M
|
| 418 |
+
condition_atomic_number_i, condition_atomic_number_j = map(lambda x: int(x), N_M_str.split())
|
| 419 |
+
condition_orbital_i, condition_orbital_j = a_b
|
| 420 |
+
|
| 421 |
+
if self.spinful:
|
| 422 |
+
if self.target == 'phiVdphi':
|
| 423 |
+
raise NotImplementedError("Not yet have support for phiVdphi")
|
| 424 |
+
else:
|
| 425 |
+
mask[:, 8 * index_out:8 * (index_out + 1)] = torch.where(
|
| 426 |
+
(atomic_number_edge_i == condition_atomic_number_i)
|
| 427 |
+
& (atomic_number_edge_j == condition_atomic_number_j),
|
| 428 |
+
1,
|
| 429 |
+
0
|
| 430 |
+
)[:, None].repeat(1, 8)
|
| 431 |
+
else:
|
| 432 |
+
if self.target == 'phiVdphi':
|
| 433 |
+
mask[:, 3 * index_out:3 * (index_out + 1)] += torch.where(
|
| 434 |
+
(atomic_number_edge_i == condition_atomic_number_i)
|
| 435 |
+
& (atomic_number_edge_j == condition_atomic_number_j),
|
| 436 |
+
1,
|
| 437 |
+
0
|
| 438 |
+
)[:, None].repeat(1, 3)
|
| 439 |
+
else:
|
| 440 |
+
mask[:, index_out] += torch.where(
|
| 441 |
+
(atomic_number_edge_i == condition_atomic_number_i)
|
| 442 |
+
& (atomic_number_edge_j == condition_atomic_number_j),
|
| 443 |
+
1,
|
| 444 |
+
0
|
| 445 |
+
)
|
| 446 |
+
|
| 447 |
+
if if_only_rc == False:
|
| 448 |
+
if self.spinful:
|
| 449 |
+
if self.target == 'phiVdphi':
|
| 450 |
+
raise NotImplementedError
|
| 451 |
+
else:
|
| 452 |
+
label[:, 8 * index_out:8 * (index_out + 1)] = torch.where(
|
| 453 |
+
(atomic_number_edge_i == condition_atomic_number_i)
|
| 454 |
+
& (atomic_number_edge_j == condition_atomic_number_j),
|
| 455 |
+
Oij_value[:, condition_orbital_i, condition_orbital_j].t(),
|
| 456 |
+
torch.zeros(8, data.edge_attr.shape[0], dtype=torch.get_default_dtype())
|
| 457 |
+
).t()
|
| 458 |
+
else:
|
| 459 |
+
if self.target == 'phiVdphi':
|
| 460 |
+
label[:, 3 * index_out:3 * (index_out + 1)] = torch.where(
|
| 461 |
+
(atomic_number_edge_i == condition_atomic_number_i)
|
| 462 |
+
& (atomic_number_edge_j == condition_atomic_number_j),
|
| 463 |
+
Oij_value[:, condition_orbital_i, condition_orbital_j].t(),
|
| 464 |
+
torch.zeros(3, data.edge_attr.shape[0], dtype=torch.get_default_dtype())
|
| 465 |
+
).t()
|
| 466 |
+
else:
|
| 467 |
+
label[:, index_out] += torch.where(
|
| 468 |
+
(atomic_number_edge_i == condition_atomic_number_i)
|
| 469 |
+
& (atomic_number_edge_j == condition_atomic_number_j),
|
| 470 |
+
Oij_value[:, condition_orbital_i, condition_orbital_j],
|
| 471 |
+
torch.zeros(data.edge_attr.shape[0], dtype=torch.get_default_dtype())
|
| 472 |
+
)
|
| 473 |
+
assert len(torch.where((mask != 1) & (mask != 0))[0]) == 0
|
| 474 |
+
mask = mask.bool()
|
| 475 |
+
data.mask = mask
|
| 476 |
+
del data.term_mask
|
| 477 |
+
if if_only_rc == False:
|
| 478 |
+
data.label = label
|
| 479 |
+
if self.target == 'hamiltonian' or self.target == 'density_matrix':
|
| 480 |
+
del data.term_real
|
| 481 |
+
elif self.target == 'O_ij':
|
| 482 |
+
del data.rh
|
| 483 |
+
del data.rdm
|
| 484 |
+
del data.rvdee
|
| 485 |
+
del data.rvxc
|
| 486 |
+
del data.rvna
|
| 487 |
+
dataset_mask.append(data)
|
| 488 |
+
return dataset_mask
|
| 489 |
+
|
| 490 |
+
def train(self, train_loader, val_loader, test_loader):
|
| 491 |
+
begin_time = time.time()
|
| 492 |
+
self.best_val_loss = 1e10
|
| 493 |
+
if self.config.getboolean('train', 'revert_then_decay'):
|
| 494 |
+
lr_step = 0
|
| 495 |
+
|
| 496 |
+
revert_decay_epoch = json.loads(self.config.get('train', 'revert_decay_epoch'))
|
| 497 |
+
revert_decay_gamma = json.loads(self.config.get('train', 'revert_decay_gamma'))
|
| 498 |
+
assert len(revert_decay_epoch) == len(revert_decay_gamma)
|
| 499 |
+
lr_step_num = len(revert_decay_epoch)
|
| 500 |
+
|
| 501 |
+
try:
|
| 502 |
+
for epoch in range(self.config.getint('train', 'epochs')):
|
| 503 |
+
if self.config.getboolean('train', 'switch_sgd') and epoch == self.config.getint('train', 'switch_sgd_epoch'):
|
| 504 |
+
model_parameters = filter(lambda p: p.requires_grad, self.model.parameters())
|
| 505 |
+
self.optimizer = optim.SGD(model_parameters, lr=self.config.getfloat('train', 'switch_sgd_lr'))
|
| 506 |
+
print(f"Switch to sgd (epoch: {epoch})")
|
| 507 |
+
|
| 508 |
+
learning_rate = self.optimizer.param_groups[0]['lr']
|
| 509 |
+
if self.if_tensorboard:
|
| 510 |
+
self.tb_writer.add_scalar('Learning rate', learning_rate, global_step=epoch)
|
| 511 |
+
|
| 512 |
+
# train
|
| 513 |
+
train_losses = self.kernel_fn(train_loader, 'TRAIN')
|
| 514 |
+
if self.if_tensorboard:
|
| 515 |
+
self.tb_writer.add_scalars('loss', {'Train loss': train_losses.avg}, global_step=epoch)
|
| 516 |
+
|
| 517 |
+
# val
|
| 518 |
+
with torch.no_grad():
|
| 519 |
+
val_losses = self.kernel_fn(val_loader, 'VAL')
|
| 520 |
+
if val_losses.avg > self.config.getfloat('train', 'revert_threshold') * self.best_val_loss:
|
| 521 |
+
print(f'Epoch #{epoch:01d} \t| '
|
| 522 |
+
f'Learning rate: {learning_rate:0.2e} \t| '
|
| 523 |
+
f'Epoch time: {time.time() - begin_time:.2f} \t| '
|
| 524 |
+
f'Train loss: {train_losses.avg:.8f} \t| '
|
| 525 |
+
f'Val loss: {val_losses.avg:.8f} \t| '
|
| 526 |
+
f'Best val loss: {self.best_val_loss:.8f}.'
|
| 527 |
+
)
|
| 528 |
+
best_checkpoint = torch.load(os.path.join(self.config.get('basic', 'save_dir'), 'best_state_dict.pkl'))
|
| 529 |
+
self.model.load_state_dict(best_checkpoint['state_dict'])
|
| 530 |
+
self.optimizer.load_state_dict(best_checkpoint['optimizer_state_dict'])
|
| 531 |
+
if self.config.getboolean('train', 'revert_then_decay'):
|
| 532 |
+
if lr_step < lr_step_num:
|
| 533 |
+
for param_group in self.optimizer.param_groups:
|
| 534 |
+
param_group['lr'] = learning_rate * revert_decay_gamma[lr_step]
|
| 535 |
+
lr_step += 1
|
| 536 |
+
with torch.no_grad():
|
| 537 |
+
val_losses = self.kernel_fn(val_loader, 'VAL')
|
| 538 |
+
print(f"Revert (threshold: {self.config.getfloat('train', 'revert_threshold')}) to epoch {best_checkpoint['epoch']} \t| Val loss: {val_losses.avg:.8f}")
|
| 539 |
+
if self.if_tensorboard:
|
| 540 |
+
self.tb_writer.add_scalars('loss', {'Validation loss': val_losses.avg}, global_step=epoch)
|
| 541 |
+
|
| 542 |
+
if self.config.get('hyperparameter', 'lr_scheduler') == 'MultiStepLR':
|
| 543 |
+
self.scheduler.step()
|
| 544 |
+
elif self.config.get('hyperparameter', 'lr_scheduler') == 'ReduceLROnPlateau':
|
| 545 |
+
self.scheduler.step(val_losses.avg)
|
| 546 |
+
elif self.config.get('hyperparameter', 'lr_scheduler') == 'CyclicLR':
|
| 547 |
+
self.scheduler.step()
|
| 548 |
+
continue
|
| 549 |
+
if self.if_tensorboard:
|
| 550 |
+
self.tb_writer.add_scalars('loss', {'Validation loss': val_losses.avg}, global_step=epoch)
|
| 551 |
+
|
| 552 |
+
if self.config.getboolean('train', 'revert_then_decay'):
|
| 553 |
+
if lr_step < lr_step_num and epoch >= revert_decay_epoch[lr_step]:
|
| 554 |
+
for param_group in self.optimizer.param_groups:
|
| 555 |
+
param_group['lr'] *= revert_decay_gamma[lr_step]
|
| 556 |
+
lr_step += 1
|
| 557 |
+
|
| 558 |
+
is_best = val_losses.avg < self.best_val_loss
|
| 559 |
+
self.best_val_loss = min(val_losses.avg, self.best_val_loss)
|
| 560 |
+
|
| 561 |
+
save_complete = False
|
| 562 |
+
while not save_complete:
|
| 563 |
+
try:
|
| 564 |
+
save_model({
|
| 565 |
+
'epoch': epoch + 1,
|
| 566 |
+
'optimizer_state_dict': self.optimizer.state_dict(),
|
| 567 |
+
'best_val_loss': self.best_val_loss,
|
| 568 |
+
'spinful': self.spinful,
|
| 569 |
+
'Z_to_index': self.Z_to_index,
|
| 570 |
+
'index_to_Z': self.index_to_Z,
|
| 571 |
+
}, {'model': self.model}, {'state_dict': self.model.state_dict()},
|
| 572 |
+
path=self.config.get('basic', 'save_dir'), is_best=is_best)
|
| 573 |
+
save_complete = True
|
| 574 |
+
except KeyboardInterrupt:
|
| 575 |
+
print('\nKeyboardInterrupt while saving model to disk')
|
| 576 |
+
|
| 577 |
+
if self.config.get('hyperparameter', 'lr_scheduler') == 'MultiStepLR':
|
| 578 |
+
self.scheduler.step()
|
| 579 |
+
elif self.config.get('hyperparameter', 'lr_scheduler') == 'ReduceLROnPlateau':
|
| 580 |
+
self.scheduler.step(val_losses.avg)
|
| 581 |
+
elif self.config.get('hyperparameter', 'lr_scheduler') == 'CyclicLR':
|
| 582 |
+
self.scheduler.step()
|
| 583 |
+
|
| 584 |
+
print(f'Epoch #{epoch:01d} \t| '
|
| 585 |
+
f'Learning rate: {learning_rate:0.2e} \t| '
|
| 586 |
+
f'Epoch time: {time.time() - begin_time:.2f} \t| '
|
| 587 |
+
f'Train loss: {train_losses.avg:.8f} \t| '
|
| 588 |
+
f'Val loss: {val_losses.avg:.8f} \t| '
|
| 589 |
+
f'Best val loss: {self.best_val_loss:.8f}.'
|
| 590 |
+
)
|
| 591 |
+
|
| 592 |
+
if val_losses.avg < self.config.getfloat('train', 'early_stopping_loss'):
|
| 593 |
+
print(f"Early stopping because the target accuracy (validation loss < {self.config.getfloat('train', 'early_stopping_loss')}) is achieved at eopch #{epoch:01d}")
|
| 594 |
+
break
|
| 595 |
+
if epoch > self.early_stopping_loss_epoch[1] and val_losses.avg < self.early_stopping_loss_epoch[0]:
|
| 596 |
+
print(f"Early stopping because the target accuracy (validation loss < {self.early_stopping_loss_epoch[0]} and epoch > {self.early_stopping_loss_epoch[1]}) is achieved at eopch #{epoch:01d}")
|
| 597 |
+
break
|
| 598 |
+
|
| 599 |
+
begin_time = time.time()
|
| 600 |
+
except KeyboardInterrupt:
|
| 601 |
+
print('\nKeyboardInterrupt')
|
| 602 |
+
|
| 603 |
+
print('---------Evaluate Model on Test Set---------------')
|
| 604 |
+
best_checkpoint = torch.load(os.path.join(self.config.get('basic', 'save_dir'), 'best_state_dict.pkl'))
|
| 605 |
+
self.model.load_state_dict(best_checkpoint['state_dict'])
|
| 606 |
+
print("=> load best checkpoint (epoch {})".format(best_checkpoint['epoch']))
|
| 607 |
+
with torch.no_grad():
|
| 608 |
+
test_csv_name = 'test_results.csv'
|
| 609 |
+
train_csv_name = 'train_results.csv'
|
| 610 |
+
val_csv_name = 'val_results.csv'
|
| 611 |
+
|
| 612 |
+
if self.config.getboolean('basic', 'save_csv'):
|
| 613 |
+
tmp = 'TEST'
|
| 614 |
+
else:
|
| 615 |
+
tmp = 'VAL'
|
| 616 |
+
test_losses = self.kernel_fn(test_loader, tmp, test_csv_name, output_E=True)
|
| 617 |
+
print(f'Test loss: {test_losses.avg:.8f}.')
|
| 618 |
+
if self.if_tensorboard:
|
| 619 |
+
self.tb_writer.add_scalars('loss', {'Test loss': test_losses.avg}, global_step=epoch)
|
| 620 |
+
test_losses = self.kernel_fn(train_loader, tmp, train_csv_name, output_E=True)
|
| 621 |
+
print(f'Train loss: {test_losses.avg:.8f}.')
|
| 622 |
+
test_losses = self.kernel_fn(val_loader, tmp, val_csv_name, output_E=True)
|
| 623 |
+
print(f'Val loss: {test_losses.avg:.8f}.')
|
| 624 |
+
|
| 625 |
+
def predict(self, hamiltonian_dirs):
|
| 626 |
+
raise NotImplementedError
|
| 627 |
+
|
| 628 |
+
def kernel_fn(self, loader, task: str, save_name=None, output_E=False):
|
| 629 |
+
assert task in ['TRAIN', 'VAL', 'TEST']
|
| 630 |
+
|
| 631 |
+
losses = LossRecord()
|
| 632 |
+
if task == 'TRAIN':
|
| 633 |
+
self.model.train()
|
| 634 |
+
else:
|
| 635 |
+
self.model.eval()
|
| 636 |
+
if task == 'TEST':
|
| 637 |
+
assert save_name != None
|
| 638 |
+
if self.target == "E_i" or self.target == "E_ij":
|
| 639 |
+
test_targets = []
|
| 640 |
+
test_preds = []
|
| 641 |
+
test_ids = []
|
| 642 |
+
test_atom_ids = []
|
| 643 |
+
test_atomic_numbers = []
|
| 644 |
+
else:
|
| 645 |
+
test_targets = []
|
| 646 |
+
test_preds = []
|
| 647 |
+
test_ids = []
|
| 648 |
+
test_atom_ids = []
|
| 649 |
+
test_atomic_numbers = []
|
| 650 |
+
test_edge_infos = []
|
| 651 |
+
|
| 652 |
+
if task != 'TRAIN' and (self.out_fea_len != 1):
|
| 653 |
+
losses_each_out = [LossRecord() for _ in range(self.out_fea_len)]
|
| 654 |
+
for step, batch_tuple in enumerate(loader):
|
| 655 |
+
if self.if_lcmp:
|
| 656 |
+
batch, subgraph = batch_tuple
|
| 657 |
+
sub_atom_idx, sub_edge_idx, sub_edge_ang, sub_index = subgraph
|
| 658 |
+
output = self.model(
|
| 659 |
+
batch.x.to(self.device),
|
| 660 |
+
batch.edge_index.to(self.device),
|
| 661 |
+
batch.edge_attr.to(self.device),
|
| 662 |
+
batch.batch.to(self.device),
|
| 663 |
+
sub_atom_idx.to(self.device),
|
| 664 |
+
sub_edge_idx.to(self.device),
|
| 665 |
+
sub_edge_ang.to(self.device),
|
| 666 |
+
sub_index.to(self.device)
|
| 667 |
+
)
|
| 668 |
+
else:
|
| 669 |
+
batch = batch_tuple
|
| 670 |
+
output = self.model(
|
| 671 |
+
batch.x.to(self.device),
|
| 672 |
+
batch.edge_index.to(self.device),
|
| 673 |
+
batch.edge_attr.to(self.device),
|
| 674 |
+
batch.batch.to(self.device)
|
| 675 |
+
)
|
| 676 |
+
if self.target == 'E_ij':
|
| 677 |
+
if self.energy_component == 'E_ij':
|
| 678 |
+
label_non_onsite = batch.E_ij.to(self.device)
|
| 679 |
+
label_onsite = batch.onsite_E_ij.to(self.device)
|
| 680 |
+
elif self.energy_component == 'summation':
|
| 681 |
+
label_non_onsite = batch.E_delta_ee_ij.to(self.device) + batch.E_xc_ij.to(self.device)
|
| 682 |
+
label_onsite = batch.onsite_E_delta_ee_ij.to(self.device) + batch.onsite_E_xc_ij.to(self.device)
|
| 683 |
+
elif self.energy_component == 'delta_ee':
|
| 684 |
+
label_non_onsite = batch.E_delta_ee_ij.to(self.device)
|
| 685 |
+
label_onsite = batch.onsite_E_delta_ee_ij.to(self.device)
|
| 686 |
+
elif self.energy_component == 'xc':
|
| 687 |
+
label_non_onsite = batch.E_xc_ij.to(self.device)
|
| 688 |
+
label_onsite = batch.onsite_E_xc_ij.to(self.device)
|
| 689 |
+
elif self.energy_component == 'both':
|
| 690 |
+
raise NotImplementedError
|
| 691 |
+
output_onsite, output_non_onsite = output
|
| 692 |
+
if self.retain_edge_fea is False:
|
| 693 |
+
output_non_onsite = output_non_onsite * 0
|
| 694 |
+
|
| 695 |
+
elif self.target == 'E_i':
|
| 696 |
+
label = batch.E_i.to(self.device)
|
| 697 |
+
output = output.reshape(label.shape)
|
| 698 |
+
else:
|
| 699 |
+
label = batch.label.to(self.device)
|
| 700 |
+
output = output.reshape(label.shape)
|
| 701 |
+
|
| 702 |
+
if self.target == 'E_i':
|
| 703 |
+
loss = self.criterion(output, label)
|
| 704 |
+
elif self.target == 'E_ij':
|
| 705 |
+
loss_Eij = self.criterion(torch.cat([output_onsite, output_non_onsite], dim=0),
|
| 706 |
+
torch.cat([label_onsite, label_non_onsite], dim=0))
|
| 707 |
+
output_non_onsite_Ei = scatter_add(output_non_onsite, batch.edge_index.to(self.device)[0, :], dim=0)
|
| 708 |
+
label_non_onsite_Ei = scatter_add(label_non_onsite, batch.edge_index.to(self.device)[0, :], dim=0)
|
| 709 |
+
output_Ei = output_non_onsite_Ei + output_onsite
|
| 710 |
+
label_Ei = label_non_onsite_Ei + label_onsite
|
| 711 |
+
loss_Ei = self.criterion(output_Ei, label_Ei)
|
| 712 |
+
loss_Etot = self.criterion(scatter_add(output_Ei, batch.batch.to(self.device), dim=0),
|
| 713 |
+
scatter_add(label_Ei, batch.batch.to(self.device), dim=0))
|
| 714 |
+
loss = loss_Eij * self.lambda_Eij + loss_Ei * self.lambda_Ei + loss_Etot * self.lambda_Etot
|
| 715 |
+
else:
|
| 716 |
+
if self.criterion_name == 'MaskMSELoss':
|
| 717 |
+
mask = batch.mask.to(self.device)
|
| 718 |
+
loss = self.criterion(output, label, mask)
|
| 719 |
+
else:
|
| 720 |
+
raise ValueError(f'Unknown criterion: {self.criterion_name}')
|
| 721 |
+
if task == 'TRAIN':
|
| 722 |
+
if self.config.get('hyperparameter', 'optimizer') == 'lbfgs':
|
| 723 |
+
def closure():
|
| 724 |
+
self.optimizer.zero_grad()
|
| 725 |
+
if self.if_lcmp:
|
| 726 |
+
output = self.model(
|
| 727 |
+
batch.x.to(self.device),
|
| 728 |
+
batch.edge_index.to(self.device),
|
| 729 |
+
batch.edge_attr.to(self.device),
|
| 730 |
+
batch.batch.to(self.device),
|
| 731 |
+
sub_atom_idx.to(self.device),
|
| 732 |
+
sub_edge_idx.to(self.device),
|
| 733 |
+
sub_edge_ang.to(self.device),
|
| 734 |
+
sub_index.to(self.device)
|
| 735 |
+
)
|
| 736 |
+
else:
|
| 737 |
+
output = self.model(
|
| 738 |
+
batch.x.to(self.device),
|
| 739 |
+
batch.edge_index.to(self.device),
|
| 740 |
+
batch.edge_attr.to(self.device),
|
| 741 |
+
batch.batch.to(self.device)
|
| 742 |
+
)
|
| 743 |
+
loss = self.criterion(output, label.to(self.device), mask)
|
| 744 |
+
loss.backward()
|
| 745 |
+
return loss
|
| 746 |
+
|
| 747 |
+
self.optimizer.step(closure)
|
| 748 |
+
else:
|
| 749 |
+
self.optimizer.zero_grad()
|
| 750 |
+
loss.backward()
|
| 751 |
+
if self.config.getboolean('train', 'clip_grad'):
|
| 752 |
+
clip_grad_norm_(self.model.parameters(), self.config.getfloat('train', 'clip_grad_value'))
|
| 753 |
+
self.optimizer.step()
|
| 754 |
+
|
| 755 |
+
if self.target == "E_i" or self.target == "E_ij":
|
| 756 |
+
losses.update(loss.item(), batch.num_nodes)
|
| 757 |
+
else:
|
| 758 |
+
if self.criterion_name == 'MaskMSELoss':
|
| 759 |
+
losses.update(loss.item(), mask.sum())
|
| 760 |
+
if task != 'TRAIN' and self.out_fea_len != 1:
|
| 761 |
+
if self.criterion_name == 'MaskMSELoss':
|
| 762 |
+
se_each_out = torch.pow(output - label.to(self.device), 2)
|
| 763 |
+
for index_out, losses_each_out_for in enumerate(losses_each_out):
|
| 764 |
+
count = mask[:, index_out].sum().item()
|
| 765 |
+
if count == 0:
|
| 766 |
+
losses_each_out_for.update(-1, 1)
|
| 767 |
+
else:
|
| 768 |
+
losses_each_out_for.update(
|
| 769 |
+
torch.masked_select(se_each_out[:, index_out], mask[:, index_out]).mean().item(),
|
| 770 |
+
count
|
| 771 |
+
)
|
| 772 |
+
if task == 'TEST':
|
| 773 |
+
if self.target == "E_ij":
|
| 774 |
+
test_targets += torch.squeeze(label_Ei.detach().cpu()).tolist()
|
| 775 |
+
test_preds += torch.squeeze(output_Ei.detach().cpu()).tolist()
|
| 776 |
+
test_ids += np.array(batch.stru_id)[torch.squeeze(batch.batch).numpy()].tolist()
|
| 777 |
+
test_atom_ids += torch.squeeze(
|
| 778 |
+
torch.tensor(range(batch.num_nodes)) - torch.tensor(batch.__slices__['x'])[
|
| 779 |
+
batch.batch]).tolist()
|
| 780 |
+
test_atomic_numbers += torch.squeeze(self.index_to_Z[batch.x]).tolist()
|
| 781 |
+
elif self.target == "E_i":
|
| 782 |
+
test_targets = torch.squeeze(label.detach().cpu()).tolist()
|
| 783 |
+
test_preds = torch.squeeze(output.detach().cpu()).tolist()
|
| 784 |
+
test_ids = np.array(batch.stru_id)[torch.squeeze(batch.batch).numpy()].tolist()
|
| 785 |
+
test_atom_ids += torch.squeeze(torch.tensor(range(batch.num_nodes)) - torch.tensor(batch.__slices__['x'])[batch.batch]).tolist()
|
| 786 |
+
test_atomic_numbers += torch.squeeze(self.index_to_Z[batch.x]).tolist()
|
| 787 |
+
else:
|
| 788 |
+
edge_stru_index = torch.squeeze(batch.batch[batch.edge_index[0]]).numpy()
|
| 789 |
+
edge_slices = torch.tensor(batch.__slices__['x'])[edge_stru_index].view(-1, 1)
|
| 790 |
+
test_preds += torch.squeeze(output.detach().cpu()).tolist()
|
| 791 |
+
test_targets += torch.squeeze(label.detach().cpu()).tolist()
|
| 792 |
+
test_ids += np.array(batch.stru_id)[edge_stru_index].tolist()
|
| 793 |
+
test_atom_ids += torch.squeeze(batch.edge_index.T - edge_slices).tolist()
|
| 794 |
+
test_atomic_numbers += torch.squeeze(self.index_to_Z[batch.x[batch.edge_index.T]]).tolist()
|
| 795 |
+
test_edge_infos += torch.squeeze(batch.edge_attr[:, :7].detach().cpu()).tolist()
|
| 796 |
+
if output_E is True:
|
| 797 |
+
if self.target == 'E_ij':
|
| 798 |
+
output_non_onsite_Ei = scatter_add(output_non_onsite, batch.edge_index.to(self.device)[1, :], dim=0)
|
| 799 |
+
label_non_onsite_Ei = scatter_add(label_non_onsite, batch.edge_index.to(self.device)[1, :], dim=0)
|
| 800 |
+
output_Ei = output_non_onsite_Ei + output_onsite
|
| 801 |
+
label_Ei = label_non_onsite_Ei + label_onsite
|
| 802 |
+
Etot_error = abs(scatter_add(output_Ei, batch.batch.to(self.device), dim=0)
|
| 803 |
+
- scatter_add(label_Ei, batch.batch.to(self.device), dim=0)).reshape(-1).tolist()
|
| 804 |
+
for test_stru_id, test_error in zip(batch.stru_id, Etot_error):
|
| 805 |
+
print(f'{test_stru_id}: {test_error * 1000:.2f} meV / unit_cell')
|
| 806 |
+
elif self.target == 'E_i':
|
| 807 |
+
Etot_error = abs(scatter_add(output, batch.batch.to(self.device), dim=0)
|
| 808 |
+
- scatter_add(label, batch.batch.to(self.device), dim=0)).reshape(-1).tolist()
|
| 809 |
+
for test_stru_id, test_error in zip(batch.stru_id, Etot_error):
|
| 810 |
+
print(f'{test_stru_id}: {test_error * 1000:.2f} meV / unit_cell')
|
| 811 |
+
|
| 812 |
+
if task != 'TRAIN' and (self.out_fea_len != 1):
|
| 813 |
+
print('%s loss each out:' % task)
|
| 814 |
+
loss_list = list(map(lambda x: f'{x.avg:0.1e}', losses_each_out))
|
| 815 |
+
print('[' + ', '.join(loss_list) + ']')
|
| 816 |
+
loss_list = list(map(lambda x: x.avg, losses_each_out))
|
| 817 |
+
print(f'max orbital: {max(loss_list):0.1e} (0-based index: {np.argmax(loss_list)})')
|
| 818 |
+
if task == 'TEST':
|
| 819 |
+
with open(os.path.join(self.config.get('basic', 'save_dir'), save_name), 'w', newline='') as f:
|
| 820 |
+
writer = csv.writer(f)
|
| 821 |
+
if self.target == "E_i" or self.target == "E_ij":
|
| 822 |
+
writer.writerow(['stru_id', 'atom_id', 'atomic_number'] +
|
| 823 |
+
['target'] * self.out_fea_len + ['pred'] * self.out_fea_len)
|
| 824 |
+
for stru_id, atom_id, atomic_number, target, pred in zip(test_ids, test_atom_ids,
|
| 825 |
+
test_atomic_numbers,
|
| 826 |
+
test_targets, test_preds):
|
| 827 |
+
if self.out_fea_len == 1:
|
| 828 |
+
writer.writerow((stru_id, atom_id, atomic_number, target, pred))
|
| 829 |
+
else:
|
| 830 |
+
writer.writerow((stru_id, atom_id, atomic_number, *target, *pred))
|
| 831 |
+
|
| 832 |
+
else:
|
| 833 |
+
writer.writerow(['stru_id', 'atom_id', 'atomic_number', 'dist', 'atom1_x', 'atom1_y', 'atom1_z',
|
| 834 |
+
'atom2_x', 'atom2_y', 'atom2_z']
|
| 835 |
+
+ ['target'] * self.out_fea_len + ['pred'] * self.out_fea_len)
|
| 836 |
+
for stru_id, atom_id, atomic_number, edge_info, target, pred in zip(test_ids, test_atom_ids,
|
| 837 |
+
test_atomic_numbers,
|
| 838 |
+
test_edge_infos, test_targets,
|
| 839 |
+
test_preds):
|
| 840 |
+
if self.out_fea_len == 1:
|
| 841 |
+
writer.writerow((stru_id, atom_id, atomic_number, *edge_info, target, pred))
|
| 842 |
+
else:
|
| 843 |
+
writer.writerow((stru_id, atom_id, atomic_number, *edge_info, *target, *pred))
|
| 844 |
+
return losses
|
3_epc/displacements/group_8/reconstruction/aohamiltonian/pred_ham_std/src/deeph/model.py
ADDED
|
@@ -0,0 +1,676 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
from typing import Union, Tuple
|
| 3 |
+
from math import ceil, sqrt
|
| 4 |
+
|
| 5 |
+
import torch
|
| 6 |
+
from torch import nn
|
| 7 |
+
import torch.nn.functional as F
|
| 8 |
+
from torch_geometric.nn.conv import MessagePassing
|
| 9 |
+
from torch_geometric.nn.norm import LayerNorm, PairNorm, InstanceNorm
|
| 10 |
+
from torch_geometric.typing import PairTensor, Adj, OptTensor, Size
|
| 11 |
+
from torch_geometric.nn.inits import glorot, zeros
|
| 12 |
+
from torch_geometric.utils import softmax
|
| 13 |
+
from torch_geometric.nn.models.dimenet import BesselBasisLayer
|
| 14 |
+
from torch_scatter import scatter_add, scatter
|
| 15 |
+
import numpy as np
|
| 16 |
+
from scipy.special import comb
|
| 17 |
+
|
| 18 |
+
from .from_se3_transformer import SphericalHarmonics
|
| 19 |
+
from .from_schnetpack import GaussianBasis
|
| 20 |
+
from .from_PyG_future import GraphNorm, DiffGroupNorm
|
| 21 |
+
from .from_HermNet import RBF, cosine_cutoff, ShiftedSoftplus, _eps
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
class ExpBernsteinBasis(nn.Module):
|
| 25 |
+
def __init__(self, K, gamma, cutoff, trainable=True):
|
| 26 |
+
super(ExpBernsteinBasis, self).__init__()
|
| 27 |
+
self.K = K
|
| 28 |
+
if trainable:
|
| 29 |
+
self.gamma = nn.Parameter(torch.tensor(gamma))
|
| 30 |
+
else:
|
| 31 |
+
self.gamma = torch.tensor(gamma)
|
| 32 |
+
self.register_buffer('cutoff', torch.tensor(cutoff))
|
| 33 |
+
self.register_buffer('comb_k', torch.Tensor(comb(K - 1, np.arange(K))))
|
| 34 |
+
|
| 35 |
+
def forward(self, distances):
|
| 36 |
+
f_zero = torch.zeros_like(distances)
|
| 37 |
+
f_cut = torch.where(distances < self.cutoff, torch.exp(
|
| 38 |
+
-(distances ** 2) / (self.cutoff ** 2 - distances ** 2)), f_zero)
|
| 39 |
+
x = torch.exp(-self.gamma * distances)
|
| 40 |
+
out = []
|
| 41 |
+
for k in range(self.K):
|
| 42 |
+
out.append((x ** k) * ((1 - x) ** (self.K - 1 - k)))
|
| 43 |
+
out = torch.stack(out, dim=-1)
|
| 44 |
+
out = out * self.comb_k[None, :] * f_cut[:, None]
|
| 45 |
+
return out
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
def get_spherical_from_cartesian(cartesian, cartesian_x=1, cartesian_y=2, cartesian_z=0):
|
| 49 |
+
spherical = torch.zeros_like(cartesian[..., 0:2])
|
| 50 |
+
r_xy = cartesian[..., cartesian_x] ** 2 + cartesian[..., cartesian_y] ** 2
|
| 51 |
+
spherical[..., 0] = torch.atan2(torch.sqrt(r_xy), cartesian[..., cartesian_z])
|
| 52 |
+
spherical[..., 1] = torch.atan2(cartesian[..., cartesian_y], cartesian[..., cartesian_x])
|
| 53 |
+
return spherical
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
class SphericalHarmonicsBasis(nn.Module):
|
| 57 |
+
def __init__(self, num_l=5):
|
| 58 |
+
super(SphericalHarmonicsBasis, self).__init__()
|
| 59 |
+
self.num_l = num_l
|
| 60 |
+
|
| 61 |
+
def forward(self, edge_attr):
|
| 62 |
+
r_vec = edge_attr[:, 1:4] - edge_attr[:, 4:7]
|
| 63 |
+
r_vec_sp = get_spherical_from_cartesian(r_vec)
|
| 64 |
+
sph_harm_func = SphericalHarmonics()
|
| 65 |
+
|
| 66 |
+
angular_expansion = []
|
| 67 |
+
for l in range(self.num_l):
|
| 68 |
+
angular_expansion.append(sph_harm_func.get(l, r_vec_sp[:, 0], r_vec_sp[:, 1]))
|
| 69 |
+
angular_expansion = torch.cat(angular_expansion, dim=-1)
|
| 70 |
+
|
| 71 |
+
return angular_expansion
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
"""
|
| 75 |
+
The class CGConv below is extended from "https://github.com/rusty1s/pytorch_geometric", which has the MIT License below
|
| 76 |
+
|
| 77 |
+
---------------------------------------------------------------------------
|
| 78 |
+
Copyright (c) 2020 Matthias Fey <matthias.fey@tu-dortmund.de>
|
| 79 |
+
|
| 80 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 81 |
+
of this software and associated documentation files (the "Software"), to deal
|
| 82 |
+
in the Software without restriction, including without limitation the rights
|
| 83 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 84 |
+
copies of the Software, and to permit persons to whom the Software is
|
| 85 |
+
furnished to do so, subject to the following conditions:
|
| 86 |
+
|
| 87 |
+
The above copyright notice and this permission notice shall be included in
|
| 88 |
+
all copies or substantial portions of the Software.
|
| 89 |
+
|
| 90 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 91 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 92 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 93 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 94 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 95 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
| 96 |
+
THE SOFTWARE.
|
| 97 |
+
"""
|
| 98 |
+
class CGConv(MessagePassing):
|
| 99 |
+
def __init__(self, channels: Union[int, Tuple[int, int]], dim: int = 0,
|
| 100 |
+
aggr: str = 'add', normalization: str = None,
|
| 101 |
+
bias: bool = True, if_exp: bool = False, **kwargs):
|
| 102 |
+
super(CGConv, self).__init__(aggr=aggr, flow="source_to_target", **kwargs)
|
| 103 |
+
self.channels = channels
|
| 104 |
+
self.dim = dim
|
| 105 |
+
self.normalization = normalization
|
| 106 |
+
self.if_exp = if_exp
|
| 107 |
+
|
| 108 |
+
if isinstance(channels, int):
|
| 109 |
+
channels = (channels, channels)
|
| 110 |
+
|
| 111 |
+
self.lin_f = nn.Linear(sum(channels) + dim, channels[1], bias=bias)
|
| 112 |
+
self.lin_s = nn.Linear(sum(channels) + dim, channels[1], bias=bias)
|
| 113 |
+
if self.normalization == 'BatchNorm':
|
| 114 |
+
self.bn = nn.BatchNorm1d(channels[1], track_running_stats=True)
|
| 115 |
+
elif self.normalization == 'LayerNorm':
|
| 116 |
+
self.ln = LayerNorm(channels[1])
|
| 117 |
+
elif self.normalization == 'PairNorm':
|
| 118 |
+
self.pn = PairNorm(channels[1])
|
| 119 |
+
elif self.normalization == 'InstanceNorm':
|
| 120 |
+
self.instance_norm = InstanceNorm(channels[1])
|
| 121 |
+
elif self.normalization == 'GraphNorm':
|
| 122 |
+
self.gn = GraphNorm(channels[1])
|
| 123 |
+
elif self.normalization == 'DiffGroupNorm':
|
| 124 |
+
self.group_norm = DiffGroupNorm(channels[1], 128)
|
| 125 |
+
elif self.normalization is None:
|
| 126 |
+
pass
|
| 127 |
+
else:
|
| 128 |
+
raise ValueError('Unknown normalization function: {}'.format(normalization))
|
| 129 |
+
|
| 130 |
+
self.reset_parameters()
|
| 131 |
+
|
| 132 |
+
def reset_parameters(self):
|
| 133 |
+
self.lin_f.reset_parameters()
|
| 134 |
+
self.lin_s.reset_parameters()
|
| 135 |
+
if self.normalization == 'BatchNorm':
|
| 136 |
+
self.bn.reset_parameters()
|
| 137 |
+
|
| 138 |
+
def forward(self, x: Union[torch.Tensor, PairTensor], edge_index: Adj,
|
| 139 |
+
edge_attr: OptTensor, batch, distance, size: Size = None) -> torch.Tensor:
|
| 140 |
+
""""""
|
| 141 |
+
if isinstance(x, torch.Tensor):
|
| 142 |
+
x: PairTensor = (x, x)
|
| 143 |
+
|
| 144 |
+
# propagate_type: (x: PairTensor, edge_attr: OptTensor)
|
| 145 |
+
out = self.propagate(edge_index, x=x, edge_attr=edge_attr, distance=distance, size=size)
|
| 146 |
+
if self.normalization == 'BatchNorm':
|
| 147 |
+
out = self.bn(out)
|
| 148 |
+
elif self.normalization == 'LayerNorm':
|
| 149 |
+
out = self.ln(out, batch)
|
| 150 |
+
elif self.normalization == 'PairNorm':
|
| 151 |
+
out = self.pn(out, batch)
|
| 152 |
+
elif self.normalization == 'InstanceNorm':
|
| 153 |
+
out = self.instance_norm(out, batch)
|
| 154 |
+
elif self.normalization == 'GraphNorm':
|
| 155 |
+
out = self.gn(out, batch)
|
| 156 |
+
elif self.normalization == 'DiffGroupNorm':
|
| 157 |
+
out = self.group_norm(out)
|
| 158 |
+
out += x[1]
|
| 159 |
+
return out
|
| 160 |
+
|
| 161 |
+
def message(self, x_i, x_j, edge_attr: OptTensor, distance) -> torch.Tensor:
|
| 162 |
+
z = torch.cat([x_i, x_j, edge_attr], dim=-1)
|
| 163 |
+
out = self.lin_f(z).sigmoid() * F.softplus(self.lin_s(z))
|
| 164 |
+
if self.if_exp:
|
| 165 |
+
sigma = 3
|
| 166 |
+
n = 2
|
| 167 |
+
out = out * torch.exp(-distance ** n / sigma ** n / 2).view(-1, 1)
|
| 168 |
+
return out
|
| 169 |
+
|
| 170 |
+
def __repr__(self):
|
| 171 |
+
return '{}({}, dim={})'.format(self.__class__.__name__, self.channels, self.dim)
|
| 172 |
+
|
| 173 |
+
|
| 174 |
+
class GAT_Crystal(MessagePassing):
|
| 175 |
+
def __init__(self, in_features, out_features, edge_dim, heads, concat=False, normalization: str = None,
|
| 176 |
+
dropout=0, bias=True, **kwargs):
|
| 177 |
+
super(GAT_Crystal, self).__init__(node_dim=0, aggr='add', flow='target_to_source', **kwargs)
|
| 178 |
+
self.in_features = in_features
|
| 179 |
+
self.out_features = out_features
|
| 180 |
+
self.heads = heads
|
| 181 |
+
self.concat = concat
|
| 182 |
+
self.dropout = dropout
|
| 183 |
+
self.neg_slope = 0.2
|
| 184 |
+
self.prelu = nn.PReLU()
|
| 185 |
+
self.bn1 = nn.BatchNorm1d(heads)
|
| 186 |
+
self.W = nn.Parameter(torch.Tensor(in_features + edge_dim, heads * out_features))
|
| 187 |
+
self.att = nn.Parameter(torch.Tensor(1, heads, 2 * out_features))
|
| 188 |
+
|
| 189 |
+
if bias and concat:
|
| 190 |
+
self.bias = nn.Parameter(torch.Tensor(heads * out_features))
|
| 191 |
+
elif bias and not concat:
|
| 192 |
+
self.bias = nn.Parameter(torch.Tensor(out_features))
|
| 193 |
+
else:
|
| 194 |
+
self.register_parameter('bias', None)
|
| 195 |
+
|
| 196 |
+
self.normalization = normalization
|
| 197 |
+
if self.normalization == 'BatchNorm':
|
| 198 |
+
self.bn = nn.BatchNorm1d(out_features, track_running_stats=True)
|
| 199 |
+
elif self.normalization == 'LayerNorm':
|
| 200 |
+
self.ln = LayerNorm(out_features)
|
| 201 |
+
elif self.normalization == 'PairNorm':
|
| 202 |
+
self.pn = PairNorm(out_features)
|
| 203 |
+
elif self.normalization == 'InstanceNorm':
|
| 204 |
+
self.instance_norm = InstanceNorm(out_features)
|
| 205 |
+
elif self.normalization == 'GraphNorm':
|
| 206 |
+
self.gn = GraphNorm(out_features)
|
| 207 |
+
elif self.normalization == 'DiffGroupNorm':
|
| 208 |
+
self.group_norm = DiffGroupNorm(out_features, 128)
|
| 209 |
+
elif self.normalization is None:
|
| 210 |
+
pass
|
| 211 |
+
else:
|
| 212 |
+
raise ValueError('Unknown normalization function: {}'.format(normalization))
|
| 213 |
+
|
| 214 |
+
self.reset_parameters()
|
| 215 |
+
|
| 216 |
+
def reset_parameters(self):
|
| 217 |
+
glorot(self.W)
|
| 218 |
+
glorot(self.att)
|
| 219 |
+
zeros(self.bias)
|
| 220 |
+
|
| 221 |
+
def forward(self, x, edge_index, edge_attr, batch, distance):
|
| 222 |
+
out = self.propagate(edge_index, x=x, edge_attr=edge_attr)
|
| 223 |
+
|
| 224 |
+
if self.normalization == 'BatchNorm':
|
| 225 |
+
out = self.bn(out)
|
| 226 |
+
elif self.normalization == 'LayerNorm':
|
| 227 |
+
out = self.ln(out, batch)
|
| 228 |
+
elif self.normalization == 'PairNorm':
|
| 229 |
+
out = self.pn(out, batch)
|
| 230 |
+
elif self.normalization == 'InstanceNorm':
|
| 231 |
+
out = self.instance_norm(out, batch)
|
| 232 |
+
elif self.normalization == 'GraphNorm':
|
| 233 |
+
out = self.gn(out, batch)
|
| 234 |
+
elif self.normalization == 'DiffGroupNorm':
|
| 235 |
+
out = self.group_norm(out)
|
| 236 |
+
return out
|
| 237 |
+
|
| 238 |
+
def message(self, edge_index_i, x_i, x_j, size_i, index, ptr: OptTensor, edge_attr):
|
| 239 |
+
x_i = torch.cat([x_i, edge_attr], dim=-1)
|
| 240 |
+
x_j = torch.cat([x_j, edge_attr], dim=-1)
|
| 241 |
+
|
| 242 |
+
x_i = F.softplus(torch.matmul(x_i, self.W))
|
| 243 |
+
x_j = F.softplus(torch.matmul(x_j, self.W))
|
| 244 |
+
x_i = x_i.view(-1, self.heads, self.out_features)
|
| 245 |
+
x_j = x_j.view(-1, self.heads, self.out_features)
|
| 246 |
+
|
| 247 |
+
alpha = F.softplus((torch.cat([x_i, x_j], dim=-1) * self.att).sum(dim=-1))
|
| 248 |
+
alpha = F.softplus(self.bn1(alpha))
|
| 249 |
+
|
| 250 |
+
alpha = softmax(alpha, index, ptr, size_i)
|
| 251 |
+
|
| 252 |
+
alpha = F.dropout(alpha, p=self.dropout, training=self.training)
|
| 253 |
+
|
| 254 |
+
return x_j * alpha.view(-1, self.heads, 1)
|
| 255 |
+
|
| 256 |
+
def update(self, aggr_out, x):
|
| 257 |
+
if self.concat is True:
|
| 258 |
+
aggr_out = aggr_out.view(-1, self.heads * self.out_features)
|
| 259 |
+
else:
|
| 260 |
+
aggr_out = aggr_out.mean(dim=1)
|
| 261 |
+
if self.bias is not None: aggr_out = aggr_out + self.bias
|
| 262 |
+
return aggr_out
|
| 263 |
+
|
| 264 |
+
|
| 265 |
+
class PaninnNodeFea():
|
| 266 |
+
def __init__(self, node_fea_s, node_fea_v=None):
|
| 267 |
+
self.node_fea_s = node_fea_s
|
| 268 |
+
if node_fea_v == None:
|
| 269 |
+
self.node_fea_v = torch.zeros(node_fea_s.shape[0], node_fea_s.shape[1], 3, dtype=node_fea_s.dtype,
|
| 270 |
+
device=node_fea_s.device)
|
| 271 |
+
else:
|
| 272 |
+
self.node_fea_v = node_fea_v
|
| 273 |
+
|
| 274 |
+
def __add__(self, other):
|
| 275 |
+
return PaninnNodeFea(self.node_fea_s + other.node_fea_s, self.node_fea_v + other.node_fea_v)
|
| 276 |
+
|
| 277 |
+
|
| 278 |
+
class PAINN(nn.Module):
|
| 279 |
+
def __init__(self, in_features, edge_dim, rc: float, l: int, normalization):
|
| 280 |
+
super(PAINN, self).__init__()
|
| 281 |
+
self.ms1 = nn.Linear(in_features, in_features)
|
| 282 |
+
self.ssp = ShiftedSoftplus()
|
| 283 |
+
self.ms2 = nn.Linear(in_features, in_features * 3)
|
| 284 |
+
|
| 285 |
+
self.rbf = RBF(rc, l)
|
| 286 |
+
self.mv = nn.Linear(l, in_features * 3)
|
| 287 |
+
self.fc = cosine_cutoff(rc)
|
| 288 |
+
|
| 289 |
+
self.us1 = nn.Linear(in_features * 2, in_features)
|
| 290 |
+
self.us2 = nn.Linear(in_features, in_features * 3)
|
| 291 |
+
|
| 292 |
+
self.normalization = normalization
|
| 293 |
+
if self.normalization == 'BatchNorm':
|
| 294 |
+
self.bn = nn.BatchNorm1d(in_features, track_running_stats=True)
|
| 295 |
+
elif self.normalization == 'LayerNorm':
|
| 296 |
+
self.ln = LayerNorm(in_features)
|
| 297 |
+
elif self.normalization == 'PairNorm':
|
| 298 |
+
self.pn = PairNorm(in_features)
|
| 299 |
+
elif self.normalization == 'InstanceNorm':
|
| 300 |
+
self.instance_norm = InstanceNorm(in_features)
|
| 301 |
+
elif self.normalization == 'GraphNorm':
|
| 302 |
+
self.gn = GraphNorm(in_features)
|
| 303 |
+
elif self.normalization == 'DiffGroupNorm':
|
| 304 |
+
self.group_norm = DiffGroupNorm(in_features, 128)
|
| 305 |
+
elif self.normalization is None or self.normalization == 'None':
|
| 306 |
+
pass
|
| 307 |
+
else:
|
| 308 |
+
raise ValueError('Unknown normalization function: {}'.format(normalization))
|
| 309 |
+
|
| 310 |
+
def forward(self, x: Union[torch.Tensor, PairTensor], edge_index: Adj,
|
| 311 |
+
edge_attr: OptTensor, batch, edge_vec) -> torch.Tensor:
|
| 312 |
+
r = torch.sqrt((edge_vec ** 2).sum(dim=-1) + _eps).unsqueeze(-1)
|
| 313 |
+
sj = x.node_fea_s[edge_index[1, :]]
|
| 314 |
+
vj = x.node_fea_v[edge_index[1, :]]
|
| 315 |
+
|
| 316 |
+
phi = self.ms2(self.ssp(self.ms1(sj)))
|
| 317 |
+
w = self.fc(r) * self.mv(self.rbf(r))
|
| 318 |
+
v_, s_, r_ = torch.chunk(phi * w, 3, dim=-1)
|
| 319 |
+
|
| 320 |
+
ds_update = s_
|
| 321 |
+
dv_update = vj * v_.unsqueeze(-1) + r_.unsqueeze(-1) * (edge_vec / r).unsqueeze(1)
|
| 322 |
+
|
| 323 |
+
ds = scatter(ds_update, edge_index[0], dim=0, dim_size=x.node_fea_s.shape[0], reduce='mean')
|
| 324 |
+
dv = scatter(dv_update, edge_index[0], dim=0, dim_size=x.node_fea_s.shape[0], reduce='mean')
|
| 325 |
+
x = x + PaninnNodeFea(ds, dv)
|
| 326 |
+
|
| 327 |
+
sj = x.node_fea_s[edge_index[1, :]]
|
| 328 |
+
vj = x.node_fea_v[edge_index[1, :]]
|
| 329 |
+
norm = torch.sqrt((vj ** 2).sum(dim=-1) + _eps)
|
| 330 |
+
s = torch.cat([norm, sj], dim=-1)
|
| 331 |
+
sj = self.us2(self.ssp(self.us1(s)))
|
| 332 |
+
|
| 333 |
+
uv = scatter(vj, edge_index[0], dim=0, dim_size=x.node_fea_s.shape[0], reduce='mean')
|
| 334 |
+
norm = torch.sqrt((uv ** 2).sum(dim=-1) + _eps).unsqueeze(-1)
|
| 335 |
+
s_ = scatter(sj, edge_index[0], dim=0, dim_size=x.node_fea_s.shape[0], reduce='mean')
|
| 336 |
+
avv, asv, ass = torch.chunk(s_, 3, dim=-1)
|
| 337 |
+
|
| 338 |
+
ds = ((uv / norm) ** 2).sum(dim=-1) * asv + ass
|
| 339 |
+
dv = uv * avv.unsqueeze(-1)
|
| 340 |
+
|
| 341 |
+
if self.normalization == 'BatchNorm':
|
| 342 |
+
ds = self.bn(ds)
|
| 343 |
+
elif self.normalization == 'LayerNorm':
|
| 344 |
+
ds = self.ln(ds, batch)
|
| 345 |
+
elif self.normalization == 'PairNorm':
|
| 346 |
+
ds = self.pn(ds, batch)
|
| 347 |
+
elif self.normalization == 'InstanceNorm':
|
| 348 |
+
ds = self.instance_norm(ds, batch)
|
| 349 |
+
elif self.normalization == 'GraphNorm':
|
| 350 |
+
ds = self.gn(ds, batch)
|
| 351 |
+
elif self.normalization == 'DiffGroupNorm':
|
| 352 |
+
ds = self.group_norm(ds)
|
| 353 |
+
|
| 354 |
+
x = x + PaninnNodeFea(ds, dv)
|
| 355 |
+
|
| 356 |
+
return x
|
| 357 |
+
|
| 358 |
+
|
| 359 |
+
class MPLayer(nn.Module):
|
| 360 |
+
def __init__(self, in_atom_fea_len, in_edge_fea_len, out_edge_fea_len, if_exp, if_edge_update, normalization,
|
| 361 |
+
atom_update_net, gauss_stop, output_layer=False):
|
| 362 |
+
super(MPLayer, self).__init__()
|
| 363 |
+
if atom_update_net == 'CGConv':
|
| 364 |
+
self.cgconv = CGConv(channels=in_atom_fea_len,
|
| 365 |
+
dim=in_edge_fea_len,
|
| 366 |
+
aggr='add',
|
| 367 |
+
normalization=normalization,
|
| 368 |
+
if_exp=if_exp)
|
| 369 |
+
elif atom_update_net == 'GAT':
|
| 370 |
+
self.cgconv = GAT_Crystal(
|
| 371 |
+
in_features=in_atom_fea_len,
|
| 372 |
+
out_features=in_atom_fea_len,
|
| 373 |
+
edge_dim=in_edge_fea_len,
|
| 374 |
+
heads=3,
|
| 375 |
+
normalization=normalization
|
| 376 |
+
)
|
| 377 |
+
elif atom_update_net == 'PAINN':
|
| 378 |
+
self.cgconv = PAINN(
|
| 379 |
+
in_features=in_atom_fea_len,
|
| 380 |
+
edge_dim=in_edge_fea_len,
|
| 381 |
+
rc=gauss_stop,
|
| 382 |
+
l=64,
|
| 383 |
+
normalization=normalization
|
| 384 |
+
)
|
| 385 |
+
|
| 386 |
+
self.if_edge_update = if_edge_update
|
| 387 |
+
self.atom_update_net = atom_update_net
|
| 388 |
+
if if_edge_update:
|
| 389 |
+
if output_layer:
|
| 390 |
+
self.e_lin = nn.Sequential(nn.Linear(in_edge_fea_len + in_atom_fea_len * 2, 128),
|
| 391 |
+
nn.SiLU(),
|
| 392 |
+
nn.Linear(128, out_edge_fea_len),
|
| 393 |
+
)
|
| 394 |
+
else:
|
| 395 |
+
self.e_lin = nn.Sequential(nn.Linear(in_edge_fea_len + in_atom_fea_len * 2, 128),
|
| 396 |
+
nn.SiLU(),
|
| 397 |
+
nn.Linear(128, out_edge_fea_len),
|
| 398 |
+
nn.SiLU(),
|
| 399 |
+
)
|
| 400 |
+
|
| 401 |
+
def forward(self, atom_fea, edge_idx, edge_fea, batch, distance, edge_vec):
|
| 402 |
+
if self.atom_update_net == 'PAINN':
|
| 403 |
+
atom_fea = self.cgconv(atom_fea, edge_idx, edge_fea, batch, edge_vec)
|
| 404 |
+
atom_fea_s = atom_fea.node_fea_s
|
| 405 |
+
else:
|
| 406 |
+
atom_fea = self.cgconv(atom_fea, edge_idx, edge_fea, batch, distance)
|
| 407 |
+
atom_fea_s = atom_fea
|
| 408 |
+
if self.if_edge_update:
|
| 409 |
+
row, col = edge_idx
|
| 410 |
+
edge_fea = self.e_lin(torch.cat([atom_fea_s[row], atom_fea_s[col], edge_fea], dim=-1))
|
| 411 |
+
return atom_fea, edge_fea
|
| 412 |
+
else:
|
| 413 |
+
return atom_fea
|
| 414 |
+
|
| 415 |
+
|
| 416 |
+
class LCMPLayer(nn.Module):
|
| 417 |
+
def __init__(self, in_atom_fea_len, in_edge_fea_len, out_edge_fea_len, num_l,
|
| 418 |
+
normalization: str = None, bias: bool = True, if_exp: bool = False):
|
| 419 |
+
super(LCMPLayer, self).__init__()
|
| 420 |
+
self.in_atom_fea_len = in_atom_fea_len
|
| 421 |
+
self.normalization = normalization
|
| 422 |
+
self.if_exp = if_exp
|
| 423 |
+
|
| 424 |
+
self.lin_f = nn.Linear(in_atom_fea_len * 2 + in_edge_fea_len, in_atom_fea_len, bias=bias)
|
| 425 |
+
self.lin_s = nn.Linear(in_atom_fea_len * 2 + in_edge_fea_len, in_atom_fea_len, bias=bias)
|
| 426 |
+
self.bn = nn.BatchNorm1d(in_atom_fea_len, track_running_stats=True)
|
| 427 |
+
|
| 428 |
+
self.e_lin = nn.Sequential(nn.Linear(in_edge_fea_len + in_atom_fea_len * 2 - num_l ** 2, 128),
|
| 429 |
+
nn.SiLU(),
|
| 430 |
+
nn.Linear(128, out_edge_fea_len)
|
| 431 |
+
)
|
| 432 |
+
self.reset_parameters()
|
| 433 |
+
|
| 434 |
+
def reset_parameters(self):
|
| 435 |
+
self.lin_f.reset_parameters()
|
| 436 |
+
self.lin_s.reset_parameters()
|
| 437 |
+
if self.normalization == 'BatchNorm':
|
| 438 |
+
self.bn.reset_parameters()
|
| 439 |
+
|
| 440 |
+
def forward(self, atom_fea, edge_fea, sub_atom_idx, sub_edge_idx, sub_edge_ang, sub_index, distance,
|
| 441 |
+
huge_structure, output_final_layer_neuron):
|
| 442 |
+
if huge_structure:
|
| 443 |
+
sub_graph_batch_num = 8
|
| 444 |
+
|
| 445 |
+
sub_graph_num = sub_atom_idx.shape[0]
|
| 446 |
+
sub_graph_batch_size = ceil(sub_graph_num / sub_graph_batch_num)
|
| 447 |
+
|
| 448 |
+
num_edge = edge_fea.shape[0]
|
| 449 |
+
vf_update = torch.zeros((num_edge * 2, self.in_atom_fea_len)).type(torch.get_default_dtype()).to(atom_fea.device)
|
| 450 |
+
for sub_graph_batch_index in range(sub_graph_batch_num):
|
| 451 |
+
if sub_graph_batch_index == sub_graph_batch_num - 1:
|
| 452 |
+
sub_graph_idx = slice(sub_graph_batch_size * sub_graph_batch_index, sub_graph_num)
|
| 453 |
+
else:
|
| 454 |
+
sub_graph_idx = slice(sub_graph_batch_size * sub_graph_batch_index,
|
| 455 |
+
sub_graph_batch_size * (sub_graph_batch_index + 1))
|
| 456 |
+
|
| 457 |
+
sub_atom_idx_batch = sub_atom_idx[sub_graph_idx]
|
| 458 |
+
sub_edge_idx_batch = sub_edge_idx[sub_graph_idx]
|
| 459 |
+
sub_edge_ang_batch = sub_edge_ang[sub_graph_idx]
|
| 460 |
+
sub_index_batch = sub_index[sub_graph_idx]
|
| 461 |
+
|
| 462 |
+
z = torch.cat([atom_fea[sub_atom_idx_batch][:, 0, :], atom_fea[sub_atom_idx_batch][:, 1, :],
|
| 463 |
+
edge_fea[sub_edge_idx_batch], sub_edge_ang_batch], dim=-1)
|
| 464 |
+
out = self.lin_f(z).sigmoid() * F.softplus(self.lin_s(z))
|
| 465 |
+
|
| 466 |
+
if self.if_exp:
|
| 467 |
+
sigma = 3
|
| 468 |
+
n = 2
|
| 469 |
+
out = out * torch.exp(-distance[sub_edge_idx_batch] ** n / sigma ** n / 2).view(-1, 1)
|
| 470 |
+
|
| 471 |
+
vf_update += scatter_add(out, sub_index_batch, dim=0, dim_size=num_edge * 2)
|
| 472 |
+
|
| 473 |
+
if self.normalization == 'BatchNorm':
|
| 474 |
+
vf_update = self.bn(vf_update)
|
| 475 |
+
vf_update = vf_update.reshape(num_edge, 2, -1)
|
| 476 |
+
if output_final_layer_neuron != '':
|
| 477 |
+
final_layer_neuron = torch.cat([vf_update[:, 0, :], vf_update[:, 1, :], edge_fea],
|
| 478 |
+
dim=-1).detach().cpu().numpy()
|
| 479 |
+
np.save(os.path.join(output_final_layer_neuron, 'final_layer_neuron.npy'), final_layer_neuron)
|
| 480 |
+
out = self.e_lin(torch.cat([vf_update[:, 0, :], vf_update[:, 1, :], edge_fea], dim=-1))
|
| 481 |
+
|
| 482 |
+
return out
|
| 483 |
+
|
| 484 |
+
num_edge = edge_fea.shape[0]
|
| 485 |
+
z = torch.cat(
|
| 486 |
+
[atom_fea[sub_atom_idx][:, 0, :], atom_fea[sub_atom_idx][:, 1, :], edge_fea[sub_edge_idx], sub_edge_ang],
|
| 487 |
+
dim=-1)
|
| 488 |
+
out = self.lin_f(z).sigmoid() * F.softplus(self.lin_s(z))
|
| 489 |
+
|
| 490 |
+
if self.if_exp:
|
| 491 |
+
sigma = 3
|
| 492 |
+
n = 2
|
| 493 |
+
out = out * torch.exp(-distance[sub_edge_idx] ** n / sigma ** n / 2).view(-1, 1)
|
| 494 |
+
|
| 495 |
+
out = scatter_add(out, sub_index, dim=0)
|
| 496 |
+
if self.normalization == 'BatchNorm':
|
| 497 |
+
out = self.bn(out)
|
| 498 |
+
out = out.reshape(num_edge, 2, -1)
|
| 499 |
+
if output_final_layer_neuron != '':
|
| 500 |
+
final_layer_neuron = torch.cat([out[:, 0, :], out[:, 1, :], edge_fea], dim=-1).detach().cpu().numpy()
|
| 501 |
+
np.save(os.path.join(output_final_layer_neuron, 'final_layer_neuron.npy'), final_layer_neuron)
|
| 502 |
+
out = self.e_lin(torch.cat([out[:, 0, :], out[:, 1, :], edge_fea], dim=-1))
|
| 503 |
+
return out
|
| 504 |
+
|
| 505 |
+
|
| 506 |
+
class MultipleLinear(nn.Module):
|
| 507 |
+
def __init__(self, num_linear: int, in_fea_len: int, out_fea_len: int, bias: bool = True) -> None:
|
| 508 |
+
super(MultipleLinear, self).__init__()
|
| 509 |
+
self.num_linear = num_linear
|
| 510 |
+
self.out_fea_len = out_fea_len
|
| 511 |
+
self.weight = nn.Parameter(torch.Tensor(num_linear, in_fea_len, out_fea_len))
|
| 512 |
+
if bias:
|
| 513 |
+
self.bias = nn.Parameter(torch.Tensor(num_linear, out_fea_len))
|
| 514 |
+
else:
|
| 515 |
+
self.register_parameter('bias', None)
|
| 516 |
+
# self.ln = LayerNorm(num_linear * out_fea_len)
|
| 517 |
+
# self.gn = GraphNorm(out_fea_len)
|
| 518 |
+
self.reset_parameters()
|
| 519 |
+
|
| 520 |
+
def reset_parameters(self) -> None:
|
| 521 |
+
nn.init.kaiming_uniform_(self.weight, a=sqrt(5))
|
| 522 |
+
if self.bias is not None:
|
| 523 |
+
fan_in, _ = nn.init._calculate_fan_in_and_fan_out(self.weight)
|
| 524 |
+
bound = 1 / sqrt(fan_in)
|
| 525 |
+
nn.init.uniform_(self.bias, -bound, bound)
|
| 526 |
+
|
| 527 |
+
def forward(self, input: torch.Tensor, batch_edge: torch.Tensor) -> torch.Tensor:
|
| 528 |
+
output = torch.matmul(input, self.weight)
|
| 529 |
+
|
| 530 |
+
if self.bias is not None:
|
| 531 |
+
output += self.bias[:, None, :]
|
| 532 |
+
return output
|
| 533 |
+
|
| 534 |
+
|
| 535 |
+
class HGNN(nn.Module):
|
| 536 |
+
def __init__(self, num_species, in_atom_fea_len, in_edge_fea_len, num_orbital,
|
| 537 |
+
distance_expansion, gauss_stop, if_exp, if_MultipleLinear, if_edge_update, if_lcmp,
|
| 538 |
+
normalization, atom_update_net, separate_onsite,
|
| 539 |
+
trainable_gaussians, type_affine, num_l=5):
|
| 540 |
+
super(HGNN, self).__init__()
|
| 541 |
+
self.num_species = num_species
|
| 542 |
+
self.embed = nn.Embedding(num_species + 5, in_atom_fea_len)
|
| 543 |
+
|
| 544 |
+
# pair-type aware affine
|
| 545 |
+
if type_affine:
|
| 546 |
+
self.type_affine = nn.Embedding(
|
| 547 |
+
num_species ** 2, 2,
|
| 548 |
+
_weight=torch.stack([torch.ones(num_species ** 2), torch.zeros(num_species ** 2)], dim=-1)
|
| 549 |
+
)
|
| 550 |
+
else:
|
| 551 |
+
self.type_affine = None
|
| 552 |
+
|
| 553 |
+
if if_edge_update or (if_edge_update is False and if_lcmp is False):
|
| 554 |
+
distance_expansion_len = in_edge_fea_len
|
| 555 |
+
else:
|
| 556 |
+
distance_expansion_len = in_edge_fea_len - num_l ** 2
|
| 557 |
+
if distance_expansion == 'GaussianBasis':
|
| 558 |
+
self.distance_expansion = GaussianBasis(
|
| 559 |
+
0.0, gauss_stop, distance_expansion_len, trainable=trainable_gaussians
|
| 560 |
+
)
|
| 561 |
+
elif distance_expansion == 'BesselBasis':
|
| 562 |
+
self.distance_expansion = BesselBasisLayer(distance_expansion_len, gauss_stop, envelope_exponent=5)
|
| 563 |
+
elif distance_expansion == 'ExpBernsteinBasis':
|
| 564 |
+
self.distance_expansion = ExpBernsteinBasis(K=distance_expansion_len, gamma=0.5, cutoff=gauss_stop,
|
| 565 |
+
trainable=True)
|
| 566 |
+
else:
|
| 567 |
+
raise ValueError('Unknown distance expansion function: {}'.format(distance_expansion))
|
| 568 |
+
|
| 569 |
+
self.if_MultipleLinear = if_MultipleLinear
|
| 570 |
+
self.if_edge_update = if_edge_update
|
| 571 |
+
self.if_lcmp = if_lcmp
|
| 572 |
+
self.atom_update_net = atom_update_net
|
| 573 |
+
self.separate_onsite = separate_onsite
|
| 574 |
+
|
| 575 |
+
if if_lcmp == True:
|
| 576 |
+
mp_output_edge_fea_len = in_edge_fea_len - num_l ** 2
|
| 577 |
+
else:
|
| 578 |
+
assert if_MultipleLinear == False
|
| 579 |
+
mp_output_edge_fea_len = in_edge_fea_len
|
| 580 |
+
|
| 581 |
+
if if_edge_update == True:
|
| 582 |
+
self.mp1 = MPLayer(in_atom_fea_len, in_edge_fea_len, in_edge_fea_len, if_exp, if_edge_update, normalization,
|
| 583 |
+
atom_update_net, gauss_stop)
|
| 584 |
+
self.mp2 = MPLayer(in_atom_fea_len, in_edge_fea_len, in_edge_fea_len, if_exp, if_edge_update, normalization,
|
| 585 |
+
atom_update_net, gauss_stop)
|
| 586 |
+
self.mp3 = MPLayer(in_atom_fea_len, in_edge_fea_len, in_edge_fea_len, if_exp, if_edge_update, normalization,
|
| 587 |
+
atom_update_net, gauss_stop)
|
| 588 |
+
self.mp4 = MPLayer(in_atom_fea_len, in_edge_fea_len, in_edge_fea_len, if_exp, if_edge_update, normalization,
|
| 589 |
+
atom_update_net, gauss_stop)
|
| 590 |
+
self.mp5 = MPLayer(in_atom_fea_len, in_edge_fea_len, mp_output_edge_fea_len, if_exp, if_edge_update,
|
| 591 |
+
normalization, atom_update_net, gauss_stop)
|
| 592 |
+
else:
|
| 593 |
+
self.mp1 = MPLayer(in_atom_fea_len, distance_expansion_len, None, if_exp, if_edge_update, normalization,
|
| 594 |
+
atom_update_net, gauss_stop)
|
| 595 |
+
self.mp2 = MPLayer(in_atom_fea_len, distance_expansion_len, None, if_exp, if_edge_update, normalization,
|
| 596 |
+
atom_update_net, gauss_stop)
|
| 597 |
+
self.mp3 = MPLayer(in_atom_fea_len, distance_expansion_len, None, if_exp, if_edge_update, normalization,
|
| 598 |
+
atom_update_net, gauss_stop)
|
| 599 |
+
self.mp4 = MPLayer(in_atom_fea_len, distance_expansion_len, None, if_exp, if_edge_update, normalization,
|
| 600 |
+
atom_update_net, gauss_stop)
|
| 601 |
+
self.mp5 = MPLayer(in_atom_fea_len, distance_expansion_len, None, if_exp, if_edge_update, normalization,
|
| 602 |
+
atom_update_net, gauss_stop)
|
| 603 |
+
|
| 604 |
+
if if_lcmp == True:
|
| 605 |
+
if self.if_MultipleLinear == True:
|
| 606 |
+
self.lcmp = LCMPLayer(in_atom_fea_len, in_edge_fea_len, 32, num_l, if_exp=if_exp)
|
| 607 |
+
self.multiple_linear1 = MultipleLinear(num_orbital, 32, 16)
|
| 608 |
+
self.multiple_linear2 = MultipleLinear(num_orbital, 16, 1)
|
| 609 |
+
else:
|
| 610 |
+
self.lcmp = LCMPLayer(in_atom_fea_len, in_edge_fea_len, num_orbital, num_l, if_exp=if_exp)
|
| 611 |
+
else:
|
| 612 |
+
self.mp_output = MPLayer(in_atom_fea_len, in_edge_fea_len, num_orbital, if_exp, if_edge_update=True,
|
| 613 |
+
normalization=normalization, atom_update_net=atom_update_net,
|
| 614 |
+
gauss_stop=gauss_stop, output_layer=True)
|
| 615 |
+
|
| 616 |
+
|
| 617 |
+
def forward(self, atom_attr, edge_idx, edge_attr, batch,
|
| 618 |
+
sub_atom_idx=None, sub_edge_idx=None, sub_edge_ang=None, sub_index=None,
|
| 619 |
+
huge_structure=False, output_final_layer_neuron=''):
|
| 620 |
+
batch_edge = batch[edge_idx[0]]
|
| 621 |
+
atom_fea0 = self.embed(atom_attr)
|
| 622 |
+
distance = edge_attr[:, 0]
|
| 623 |
+
edge_vec = edge_attr[:, 1:4] - edge_attr[:, 4:7]
|
| 624 |
+
if self.type_affine is None:
|
| 625 |
+
edge_fea0 = self.distance_expansion(distance)
|
| 626 |
+
else:
|
| 627 |
+
affine_coeff = self.type_affine(self.num_species * atom_attr[edge_idx[0]] + atom_attr[edge_idx[1]])
|
| 628 |
+
edge_fea0 = self.distance_expansion(distance * affine_coeff[:, 0] + affine_coeff[:, 1])
|
| 629 |
+
if self.atom_update_net == "PAINN":
|
| 630 |
+
atom_fea0 = PaninnNodeFea(atom_fea0)
|
| 631 |
+
|
| 632 |
+
if self.if_edge_update == True:
|
| 633 |
+
atom_fea, edge_fea = self.mp1(atom_fea0, edge_idx, edge_fea0, batch, distance, edge_vec)
|
| 634 |
+
atom_fea, edge_fea = self.mp2(atom_fea, edge_idx, edge_fea, batch, distance, edge_vec)
|
| 635 |
+
atom_fea0, edge_fea0 = atom_fea0 + atom_fea, edge_fea0 + edge_fea
|
| 636 |
+
atom_fea, edge_fea = self.mp3(atom_fea0, edge_idx, edge_fea0, batch, distance, edge_vec)
|
| 637 |
+
atom_fea, edge_fea = self.mp4(atom_fea, edge_idx, edge_fea, batch, distance, edge_vec)
|
| 638 |
+
atom_fea0, edge_fea0 = atom_fea0 + atom_fea, edge_fea0 + edge_fea
|
| 639 |
+
atom_fea, edge_fea = self.mp5(atom_fea0, edge_idx, edge_fea0, batch, distance, edge_vec)
|
| 640 |
+
|
| 641 |
+
if self.if_lcmp == True:
|
| 642 |
+
if self.atom_update_net == 'PAINN':
|
| 643 |
+
atom_fea_s = atom_fea.node_fea_s
|
| 644 |
+
else:
|
| 645 |
+
atom_fea_s = atom_fea
|
| 646 |
+
out = self.lcmp(atom_fea_s, edge_fea, sub_atom_idx, sub_edge_idx, sub_edge_ang, sub_index, distance,
|
| 647 |
+
huge_structure, output_final_layer_neuron)
|
| 648 |
+
else:
|
| 649 |
+
atom_fea, edge_fea = self.mp_output(atom_fea, edge_idx, edge_fea, batch, distance, edge_vec)
|
| 650 |
+
out = edge_fea
|
| 651 |
+
else:
|
| 652 |
+
atom_fea = self.mp1(atom_fea0, edge_idx, edge_fea0, batch, distance, edge_vec)
|
| 653 |
+
atom_fea = self.mp2(atom_fea, edge_idx, edge_fea0, batch, distance, edge_vec)
|
| 654 |
+
atom_fea0 = atom_fea0 + atom_fea
|
| 655 |
+
atom_fea = self.mp3(atom_fea0, edge_idx, edge_fea0, batch, distance, edge_vec)
|
| 656 |
+
atom_fea = self.mp4(atom_fea, edge_idx, edge_fea0, batch, distance, edge_vec)
|
| 657 |
+
atom_fea0 = atom_fea0 + atom_fea
|
| 658 |
+
atom_fea = self.mp5(atom_fea0, edge_idx, edge_fea0, batch, distance, edge_vec)
|
| 659 |
+
|
| 660 |
+
if self.atom_update_net == 'PAINN':
|
| 661 |
+
atom_fea_s = atom_fea.node_fea_s
|
| 662 |
+
else:
|
| 663 |
+
atom_fea_s = atom_fea
|
| 664 |
+
if self.if_lcmp == True:
|
| 665 |
+
out = self.lcmp(atom_fea_s, edge_fea0, sub_atom_idx, sub_edge_idx, sub_edge_ang, sub_index, distance,
|
| 666 |
+
huge_structure, output_final_layer_neuron)
|
| 667 |
+
else:
|
| 668 |
+
atom_fea, edge_fea = self.mp_output(atom_fea, edge_idx, edge_fea0, batch, distance, edge_vec)
|
| 669 |
+
out = edge_fea
|
| 670 |
+
|
| 671 |
+
if self.if_MultipleLinear == True:
|
| 672 |
+
out = self.multiple_linear1(F.silu(out), batch_edge)
|
| 673 |
+
out = self.multiple_linear2(F.silu(out), batch_edge)
|
| 674 |
+
out = out.T
|
| 675 |
+
|
| 676 |
+
return out
|
3_epc/displacements/group_8/reconstruction/aohamiltonian/pred_ham_std/src/deeph/preprocess/__init__.py
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from .openmx_parse import OijLoad, GetEEiEij, openmx_parse_overlap
|
| 2 |
+
from .get_rc import get_rc
|
| 3 |
+
from .abacus_get_data import abacus_parse
|
| 4 |
+
from .siesta_get_data import siesta_parse
|
3_epc/displacements/group_8/reconstruction/aohamiltonian/pred_ham_std/src/deeph/preprocess/__pycache__/abacus_get_data.cpython-312.pyc
ADDED
|
Binary file (23 kB). View file
|
|
|
3_epc/displacements/group_8/reconstruction/aohamiltonian/pred_ham_std/src/deeph/preprocess/__pycache__/get_rc.cpython-312.pyc
ADDED
|
Binary file (11.2 kB). View file
|
|
|
3_epc/displacements/group_8/reconstruction/aohamiltonian/pred_ham_std/src/deeph/preprocess/abacus_get_data.py
ADDED
|
@@ -0,0 +1,340 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Script for interface from ABACUS (http://abacus.ustc.edu.cn/) to DeepH-pack
|
| 2 |
+
# Coded by ZC Tang @ Tsinghua Univ. e-mail: az_txycha@126.com
|
| 3 |
+
# Modified by He Li @ Tsinghua Univ. & XY Zhou @ Peking Univ.
|
| 4 |
+
# To use this script, please add 'out_mat_hs2 1' in ABACUS INPUT File
|
| 5 |
+
# Current version is capable of coping with f-orbitals
|
| 6 |
+
# 20220717: Read structure from running_scf.log
|
| 7 |
+
# 20220919: The suffix of the output sub-directories (OUT.suffix) can be set by ["basic"]["abacus_suffix"] keyword in preprocess.ini
|
| 8 |
+
# 20220920: Supporting cartesian coordinates in the log file
|
| 9 |
+
# 20231228: Supporting ABACUS v3.4
|
| 10 |
+
|
| 11 |
+
import os
|
| 12 |
+
import sys
|
| 13 |
+
import json
|
| 14 |
+
import re
|
| 15 |
+
|
| 16 |
+
import numpy as np
|
| 17 |
+
from scipy.sparse import csr_matrix
|
| 18 |
+
from scipy.linalg import block_diag
|
| 19 |
+
import argparse
|
| 20 |
+
import h5py
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
Bohr2Ang = 0.529177249
|
| 24 |
+
periodic_table = {'Ac': 89, 'Ag': 47, 'Al': 13, 'Am': 95, 'Ar': 18, 'As': 33, 'At': 85, 'Au': 79, 'B': 5, 'Ba': 56,
|
| 25 |
+
'Be': 4, 'Bi': 83, 'Bk': 97, 'Br': 35, 'C': 6, 'Ca': 20, 'Cd': 48, 'Ce': 58, 'Cf': 98, 'Cl': 17,
|
| 26 |
+
'Cm': 96, 'Co': 27, 'Cr': 24, 'Cs': 55, 'Cu': 29, 'Dy': 66, 'Er': 68, 'Es': 99, 'Eu': 63, 'F': 9,
|
| 27 |
+
'Fe': 26, 'Fm': 100, 'Fr': 87, 'Ga': 31, 'Gd': 64, 'Ge': 32, 'H': 1, 'He': 2, 'Hf': 72, 'Hg': 80,
|
| 28 |
+
'Ho': 67, 'I': 53, 'In': 49, 'Ir': 77, 'K': 19, 'Kr': 36, 'La': 57, 'Li': 3, 'Lr': 103, 'Lu': 71,
|
| 29 |
+
'Md': 101, 'Mg': 12, 'Mn': 25, 'Mo': 42, 'N': 7, 'Na': 11, 'Nb': 41, 'Nd': 60, 'Ne': 10, 'Ni': 28,
|
| 30 |
+
'No': 102, 'Np': 93, 'O': 8, 'Os': 76, 'P': 15, 'Pa': 91, 'Pb': 82, 'Pd': 46, 'Pm': 61, 'Po': 84,
|
| 31 |
+
'Pr': 59, 'Pt': 78, 'Pu': 94, 'Ra': 88, 'Rb': 37, 'Re': 75, 'Rh': 45, 'Rn': 86, 'Ru': 44, 'S': 16,
|
| 32 |
+
'Sb': 51, 'Sc': 21, 'Se': 34, 'Si': 14, 'Sm': 62, 'Sn': 50, 'Sr': 38, 'Ta': 73, 'Tb': 65, 'Tc': 43,
|
| 33 |
+
'Te': 52, 'Th': 90, 'Ti': 22, 'Tl': 81, 'Tm': 69, 'U': 92, 'V': 23, 'W': 74, 'Xe': 54, 'Y': 39,
|
| 34 |
+
'Yb': 70, 'Zn': 30, 'Zr': 40, 'Rf': 104, 'Db': 105, 'Sg': 106, 'Bh': 107, 'Hs': 108, 'Mt': 109,
|
| 35 |
+
'Ds': 110, 'Rg': 111, 'Cn': 112, 'Nh': 113, 'Fl': 114, 'Mc': 115, 'Lv': 116, 'Ts': 117, 'Og': 118}
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
class OrbAbacus2DeepH:
|
| 39 |
+
def __init__(self):
|
| 40 |
+
self.Us_abacus2deeph = {}
|
| 41 |
+
self.Us_abacus2deeph[0] = np.eye(1)
|
| 42 |
+
self.Us_abacus2deeph[1] = np.eye(3)[[1, 2, 0]]
|
| 43 |
+
self.Us_abacus2deeph[2] = np.eye(5)[[0, 3, 4, 1, 2]]
|
| 44 |
+
self.Us_abacus2deeph[3] = np.eye(7)[[0, 1, 2, 3, 4, 5, 6]]
|
| 45 |
+
|
| 46 |
+
minus_dict = {
|
| 47 |
+
1: [0, 1],
|
| 48 |
+
2: [3, 4],
|
| 49 |
+
3: [1, 2, 5, 6],
|
| 50 |
+
}
|
| 51 |
+
for k, v in minus_dict.items():
|
| 52 |
+
self.Us_abacus2deeph[k][v] *= -1
|
| 53 |
+
|
| 54 |
+
def get_U(self, l):
|
| 55 |
+
if l > 3:
|
| 56 |
+
raise NotImplementedError("Only support l = s, p, d, f")
|
| 57 |
+
return self.Us_abacus2deeph[l]
|
| 58 |
+
|
| 59 |
+
def transform(self, mat, l_lefts, l_rights):
|
| 60 |
+
block_lefts = block_diag(*[self.get_U(l_left) for l_left in l_lefts])
|
| 61 |
+
block_rights = block_diag(*[self.get_U(l_right) for l_right in l_rights])
|
| 62 |
+
return block_lefts @ mat @ block_rights.T
|
| 63 |
+
|
| 64 |
+
def abacus_parse(input_path, output_path, data_name, only_S=False, get_r=False):
|
| 65 |
+
input_path = os.path.abspath(input_path)
|
| 66 |
+
output_path = os.path.abspath(output_path)
|
| 67 |
+
os.makedirs(output_path, exist_ok=True)
|
| 68 |
+
|
| 69 |
+
def find_target_line(f, target):
|
| 70 |
+
line = f.readline()
|
| 71 |
+
while line:
|
| 72 |
+
if target in line:
|
| 73 |
+
return line
|
| 74 |
+
line = f.readline()
|
| 75 |
+
return None
|
| 76 |
+
if only_S:
|
| 77 |
+
log_file_name = "running_get_S.log"
|
| 78 |
+
else:
|
| 79 |
+
log_file_name = "running_scf.log"
|
| 80 |
+
with open(os.path.join(input_path, data_name, log_file_name), 'r') as f:
|
| 81 |
+
f.readline()
|
| 82 |
+
line = f.readline()
|
| 83 |
+
# assert "WELCOME TO ABACUS" in line
|
| 84 |
+
assert find_target_line(f, "READING UNITCELL INFORMATION") is not None, 'Cannot find "READING UNITCELL INFORMATION" in log file'
|
| 85 |
+
num_atom_type = int(f.readline().split()[-1])
|
| 86 |
+
|
| 87 |
+
assert find_target_line(f, "lattice constant (Bohr)") is not None
|
| 88 |
+
lattice_constant = float(f.readline().split()[-1]) # unit is Angstrom
|
| 89 |
+
|
| 90 |
+
site_norbits_dict = {}
|
| 91 |
+
orbital_types_dict = {}
|
| 92 |
+
for index_type in range(num_atom_type):
|
| 93 |
+
tmp = find_target_line(f, "READING ATOM TYPE")
|
| 94 |
+
assert tmp is not None, 'Cannot find "ATOM TYPE" in log file'
|
| 95 |
+
assert tmp.split()[-1] == str(index_type + 1)
|
| 96 |
+
if tmp is None:
|
| 97 |
+
raise Exception(f"Cannot find ATOM {index_type} in {log_file_name}")
|
| 98 |
+
|
| 99 |
+
line = f.readline()
|
| 100 |
+
assert "atom label =" in line
|
| 101 |
+
atom_label = line.split()[-1]
|
| 102 |
+
assert atom_label in periodic_table, "Atom label should be in periodic table"
|
| 103 |
+
atom_type = periodic_table[atom_label]
|
| 104 |
+
|
| 105 |
+
current_site_norbits = 0
|
| 106 |
+
current_orbital_types = []
|
| 107 |
+
while True:
|
| 108 |
+
line = f.readline()
|
| 109 |
+
if "number of zeta" in line:
|
| 110 |
+
tmp = line.split()
|
| 111 |
+
L = int(tmp[0][2:-1])
|
| 112 |
+
num_L = int(tmp[-1])
|
| 113 |
+
current_site_norbits += (2 * L + 1) * num_L
|
| 114 |
+
current_orbital_types.extend([L] * num_L)
|
| 115 |
+
else:
|
| 116 |
+
break
|
| 117 |
+
site_norbits_dict[atom_type] = current_site_norbits
|
| 118 |
+
orbital_types_dict[atom_type] = current_orbital_types
|
| 119 |
+
|
| 120 |
+
line = find_target_line(f, "TOTAL ATOM NUMBER")
|
| 121 |
+
assert line is not None, 'Cannot find "TOTAL ATOM NUMBER" in log file'
|
| 122 |
+
nsites = int(line.split()[-1])
|
| 123 |
+
|
| 124 |
+
line = find_target_line(f, " COORDINATES")
|
| 125 |
+
assert line is not None, 'Cannot find "DIRECT COORDINATES" or "CARTESIAN COORDINATES" in log file'
|
| 126 |
+
if "DIRECT" in line:
|
| 127 |
+
coords_type = "direct"
|
| 128 |
+
elif "CARTESIAN" in line:
|
| 129 |
+
coords_type = "cartesian"
|
| 130 |
+
else:
|
| 131 |
+
raise ValueError('Cannot find "DIRECT COORDINATES" or "CARTESIAN COORDINATES" in log file')
|
| 132 |
+
|
| 133 |
+
assert "atom" in f.readline()
|
| 134 |
+
frac_coords = np.zeros((nsites, 3))
|
| 135 |
+
site_norbits = np.zeros(nsites, dtype=int)
|
| 136 |
+
element = np.zeros(nsites, dtype=int)
|
| 137 |
+
for index_site in range(nsites):
|
| 138 |
+
line = f.readline()
|
| 139 |
+
tmp = line.split()
|
| 140 |
+
assert "tau" in tmp[0]
|
| 141 |
+
atom_label = ''.join(re.findall(r'[A-Za-z]', tmp[0][5:]))
|
| 142 |
+
assert atom_label in periodic_table, "Atom label should be in periodic table"
|
| 143 |
+
element[index_site] = periodic_table[atom_label]
|
| 144 |
+
site_norbits[index_site] = site_norbits_dict[element[index_site]]
|
| 145 |
+
frac_coords[index_site, :] = np.array(tmp[1:4])
|
| 146 |
+
norbits = int(np.sum(site_norbits))
|
| 147 |
+
site_norbits_cumsum = np.cumsum(site_norbits)
|
| 148 |
+
|
| 149 |
+
assert find_target_line(f, "Lattice vectors: (Cartesian coordinate: in unit of a_0)") is not None
|
| 150 |
+
lattice = np.zeros((3, 3))
|
| 151 |
+
for index_lat in range(3):
|
| 152 |
+
lattice[index_lat, :] = np.array(f.readline().split())
|
| 153 |
+
if coords_type == "cartesian":
|
| 154 |
+
frac_coords = frac_coords @ np.matrix(lattice).I
|
| 155 |
+
lattice = lattice * lattice_constant
|
| 156 |
+
if only_S:
|
| 157 |
+
spinful = False
|
| 158 |
+
else:
|
| 159 |
+
line = find_target_line(f, "NSPIN")
|
| 160 |
+
assert line is not None, 'Cannot find "NSPIN" in log file'
|
| 161 |
+
if "NSPIN == 1" in line:
|
| 162 |
+
spinful = False
|
| 163 |
+
elif "NSPIN == 4" in line:
|
| 164 |
+
spinful = True
|
| 165 |
+
else:
|
| 166 |
+
raise ValueError(f'{line} is not supported')
|
| 167 |
+
if only_S:
|
| 168 |
+
fermi_level = 0.0
|
| 169 |
+
else:
|
| 170 |
+
with open(os.path.join(input_path, data_name, log_file_name), 'r') as f:
|
| 171 |
+
line = find_target_line(f, "EFERMI")
|
| 172 |
+
assert line is not None, 'Cannot find "EFERMI" in log file'
|
| 173 |
+
assert "eV" in line
|
| 174 |
+
fermi_level = float(line.split()[2])
|
| 175 |
+
assert find_target_line(f, "EFERMI") is None, "There is more than one EFERMI in log file"
|
| 176 |
+
|
| 177 |
+
np.savetxt(os.path.join(output_path, "lat.dat"), np.transpose(lattice))
|
| 178 |
+
np.savetxt(os.path.join(output_path, "rlat.dat"), np.linalg.inv(lattice) * 2 * np.pi)
|
| 179 |
+
cart_coords = frac_coords @ lattice
|
| 180 |
+
np.savetxt(os.path.join(output_path, "site_positions.dat").format(output_path), np.transpose(cart_coords))
|
| 181 |
+
np.savetxt(os.path.join(output_path, "element.dat"), element, fmt='%d')
|
| 182 |
+
info = {'nsites' : nsites, 'isorthogonal': False, 'isspinful': spinful, 'norbits': norbits, 'fermi_level': fermi_level}
|
| 183 |
+
with open('{}/info.json'.format(output_path), 'w') as info_f:
|
| 184 |
+
json.dump(info, info_f)
|
| 185 |
+
with open(os.path.join(output_path, "orbital_types.dat"), 'w') as f:
|
| 186 |
+
for atomic_number in element:
|
| 187 |
+
for index_l, l in enumerate(orbital_types_dict[atomic_number]):
|
| 188 |
+
if index_l == 0:
|
| 189 |
+
f.write(str(l))
|
| 190 |
+
else:
|
| 191 |
+
f.write(f" {l}")
|
| 192 |
+
f.write('\n')
|
| 193 |
+
|
| 194 |
+
U_orbital = OrbAbacus2DeepH()
|
| 195 |
+
def parse_matrix(matrix_path, factor, spinful=False):
|
| 196 |
+
matrix_dict = dict()
|
| 197 |
+
with open(matrix_path, 'r') as f:
|
| 198 |
+
line = f.readline() # read "Matrix Dimension of ..."
|
| 199 |
+
if not "Matrix Dimension of" in line:
|
| 200 |
+
line = f.readline() # ABACUS >= 3.0
|
| 201 |
+
assert "Matrix Dimension of" in line
|
| 202 |
+
f.readline() # read "Matrix number of ..."
|
| 203 |
+
norbits = int(line.split()[-1])
|
| 204 |
+
for line in f:
|
| 205 |
+
line1 = line.split()
|
| 206 |
+
if len(line1) == 0:
|
| 207 |
+
break
|
| 208 |
+
num_element = int(line1[3])
|
| 209 |
+
if num_element != 0:
|
| 210 |
+
R_cur = np.array(line1[:3]).astype(int)
|
| 211 |
+
line2 = f.readline().split()
|
| 212 |
+
line3 = f.readline().split()
|
| 213 |
+
line4 = f.readline().split()
|
| 214 |
+
if not spinful:
|
| 215 |
+
hamiltonian_cur = csr_matrix((np.array(line2).astype(float), np.array(line3).astype(int),
|
| 216 |
+
np.array(line4).astype(int)), shape=(norbits, norbits)).toarray()
|
| 217 |
+
else:
|
| 218 |
+
line2 = np.char.replace(line2, '(', '')
|
| 219 |
+
line2 = np.char.replace(line2, ')', 'j')
|
| 220 |
+
line2 = np.char.replace(line2, ',', '+')
|
| 221 |
+
line2 = np.char.replace(line2, '+-', '-')
|
| 222 |
+
hamiltonian_cur = csr_matrix((np.array(line2).astype(np.complex128), np.array(line3).astype(int),
|
| 223 |
+
np.array(line4).astype(int)), shape=(norbits, norbits)).toarray()
|
| 224 |
+
for index_site_i in range(nsites):
|
| 225 |
+
for index_site_j in range(nsites):
|
| 226 |
+
key_str = f"[{R_cur[0]}, {R_cur[1]}, {R_cur[2]}, {index_site_i + 1}, {index_site_j + 1}]"
|
| 227 |
+
mat = hamiltonian_cur[(site_norbits_cumsum[index_site_i]
|
| 228 |
+
- site_norbits[index_site_i]) * (1 + spinful):
|
| 229 |
+
site_norbits_cumsum[index_site_i] * (1 + spinful),
|
| 230 |
+
(site_norbits_cumsum[index_site_j] - site_norbits[index_site_j]) * (1 + spinful):
|
| 231 |
+
site_norbits_cumsum[index_site_j] * (1 + spinful)]
|
| 232 |
+
if abs(mat).max() < 1e-8:
|
| 233 |
+
continue
|
| 234 |
+
if not spinful:
|
| 235 |
+
mat = U_orbital.transform(mat, orbital_types_dict[element[index_site_i]],
|
| 236 |
+
orbital_types_dict[element[index_site_j]])
|
| 237 |
+
else:
|
| 238 |
+
mat = mat.reshape((site_norbits[index_site_i], 2, site_norbits[index_site_j], 2))
|
| 239 |
+
mat = mat.transpose((1, 0, 3, 2)).reshape((2 * site_norbits[index_site_i],
|
| 240 |
+
2 * site_norbits[index_site_j]))
|
| 241 |
+
mat = U_orbital.transform(mat, orbital_types_dict[element[index_site_i]] * 2,
|
| 242 |
+
orbital_types_dict[element[index_site_j]] * 2)
|
| 243 |
+
matrix_dict[key_str] = mat * factor
|
| 244 |
+
return matrix_dict, norbits
|
| 245 |
+
|
| 246 |
+
if only_S:
|
| 247 |
+
overlap_dict, tmp = parse_matrix(os.path.join(input_path, "SR.csr"), 1)
|
| 248 |
+
assert tmp == norbits
|
| 249 |
+
else:
|
| 250 |
+
hamiltonian_dict, tmp = parse_matrix(
|
| 251 |
+
os.path.join(input_path, data_name, "data-HR-sparse_SPIN0.csr"), 13.605698, # Ryd2eV
|
| 252 |
+
spinful=spinful)
|
| 253 |
+
assert tmp == norbits * (1 + spinful)
|
| 254 |
+
overlap_dict, tmp = parse_matrix(os.path.join(input_path, data_name, "data-SR-sparse_SPIN0.csr"), 1,
|
| 255 |
+
spinful=spinful)
|
| 256 |
+
assert tmp == norbits * (1 + spinful)
|
| 257 |
+
if spinful:
|
| 258 |
+
overlap_dict_spinless = {}
|
| 259 |
+
for k, v in overlap_dict.items():
|
| 260 |
+
overlap_dict_spinless[k] = v[:v.shape[0] // 2, :v.shape[1] // 2].real
|
| 261 |
+
overlap_dict_spinless, overlap_dict = overlap_dict, overlap_dict_spinless
|
| 262 |
+
|
| 263 |
+
if not only_S:
|
| 264 |
+
with h5py.File(os.path.join(output_path, "hamiltonians.h5"), 'w') as fid:
|
| 265 |
+
for key_str, value in hamiltonian_dict.items():
|
| 266 |
+
fid[key_str] = value
|
| 267 |
+
with h5py.File(os.path.join(output_path, "overlaps.h5"), 'w') as fid:
|
| 268 |
+
for key_str, value in overlap_dict.items():
|
| 269 |
+
fid[key_str] = value
|
| 270 |
+
if get_r:
|
| 271 |
+
def parse_r_matrix(matrix_path, factor):
|
| 272 |
+
matrix_dict = dict()
|
| 273 |
+
with open(matrix_path, 'r') as f:
|
| 274 |
+
line = f.readline();
|
| 275 |
+
norbits = int(line.split()[-1])
|
| 276 |
+
for line in f:
|
| 277 |
+
line1 = line.split()
|
| 278 |
+
if len(line1) == 0:
|
| 279 |
+
break
|
| 280 |
+
assert len(line1) > 3
|
| 281 |
+
R_cur = np.array(line1[:3]).astype(int)
|
| 282 |
+
mat_cur = np.zeros((3, norbits * norbits))
|
| 283 |
+
for line_index in range(norbits * norbits):
|
| 284 |
+
line_mat = f.readline().split()
|
| 285 |
+
assert len(line_mat) == 3
|
| 286 |
+
mat_cur[:, line_index] = np.array(line_mat)
|
| 287 |
+
mat_cur = mat_cur.reshape((3, norbits, norbits))
|
| 288 |
+
|
| 289 |
+
for index_site_i in range(nsites):
|
| 290 |
+
for index_site_j in range(nsites):
|
| 291 |
+
for direction in range(3):
|
| 292 |
+
key_str = f"[{R_cur[0]}, {R_cur[1]}, {R_cur[2]}, {index_site_i + 1}, {index_site_j + 1}, {direction + 1}]"
|
| 293 |
+
mat = mat_cur[direction, site_norbits_cumsum[index_site_i]
|
| 294 |
+
- site_norbits[index_site_i]:site_norbits_cumsum[index_site_i],
|
| 295 |
+
site_norbits_cumsum[index_site_j]
|
| 296 |
+
- site_norbits[index_site_j]:site_norbits_cumsum[index_site_j]]
|
| 297 |
+
if abs(mat).max() < 1e-8:
|
| 298 |
+
continue
|
| 299 |
+
mat = U_orbital.transform(mat, orbital_types_dict[element[index_site_i]],
|
| 300 |
+
orbital_types_dict[element[index_site_j]])
|
| 301 |
+
matrix_dict[key_str] = mat * factor
|
| 302 |
+
return matrix_dict, norbits
|
| 303 |
+
position_dict, tmp = parse_r_matrix(os.path.join(input_path, data_name, "data-rR-tr_SPIN1"), 0.529177249) # Bohr2Ang
|
| 304 |
+
assert tmp == norbits
|
| 305 |
+
|
| 306 |
+
with h5py.File(os.path.join(output_path, "positions.h5"), 'w') as fid:
|
| 307 |
+
for key_str, value in position_dict.items():
|
| 308 |
+
fid[key_str] = value
|
| 309 |
+
|
| 310 |
+
|
| 311 |
+
if __name__ == '__main__':
|
| 312 |
+
parser = argparse.ArgumentParser(description='Predict Hamiltonian')
|
| 313 |
+
parser.add_argument(
|
| 314 |
+
'-i','--input_dir', type=str, default='./',
|
| 315 |
+
help='path of output subdirectory'
|
| 316 |
+
)
|
| 317 |
+
parser.add_argument(
|
| 318 |
+
'-o','--output_dir', type=str, default='./',
|
| 319 |
+
help='path of output .h5 and .dat'
|
| 320 |
+
)
|
| 321 |
+
parser.add_argument(
|
| 322 |
+
'-a','--abacus_suffix', type=str, default='ABACUS',
|
| 323 |
+
help='suffix of output subdirectory'
|
| 324 |
+
)
|
| 325 |
+
parser.add_argument(
|
| 326 |
+
'-S','--only_S', type=int, default=0
|
| 327 |
+
)
|
| 328 |
+
parser.add_argument(
|
| 329 |
+
'-g','--get_r', type=int, default=0
|
| 330 |
+
)
|
| 331 |
+
args = parser.parse_args()
|
| 332 |
+
|
| 333 |
+
input_path = args.input_dir
|
| 334 |
+
output_path = args.output_dir
|
| 335 |
+
data_name = "OUT." + args.abacus_suffix
|
| 336 |
+
only_S = bool(args.only_S)
|
| 337 |
+
get_r = bool(args.get_r)
|
| 338 |
+
print("only_S: {}".format(only_S))
|
| 339 |
+
print("get_r: {}".format(get_r))
|
| 340 |
+
abacus_parse(input_path, output_path, data_name, only_S, get_r)
|