Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NRL update #57

Merged
merged 5 commits into from
Dec 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions dptb/entrypoints/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from dptb.entrypoints.test import _test
from dptb.entrypoints.run import run
from dptb.entrypoints.bond import bond
from dptb.entrypoints.nrl2json import nrl2json
from dptb.utils.loggers import set_log_handles

def get_ll(log_level: str) -> int:
Expand Down Expand Up @@ -111,6 +112,33 @@ def main_parser() -> argparse.ArgumentParser:
help="The cutoff radius of bond search.",
)

# nrl2json
parser_nrl2json = subparsers.add_parser(
"n2j",
parents=[parser_log],
help="using DeePTB tools to convert NRL file to json model.",
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
)
parser_nrl2json.add_argument(
"INPUT", help="the input parameter file in json or yaml format",
type=str,
default=None
)
parser_nrl2json.add_argument(
"-nrl",
"--nrl_file",
type=str,
default=None,
help="The NRL file name"
)
parser_nrl2json.add_argument(
"-o",
"--outdir",
type=str,
default="./",
help="The output files to save the transfered model and updated input."
)

# train parser
parser_train = subparsers.add_parser(
"train",
Expand Down Expand Up @@ -321,3 +349,6 @@ def main():

elif args.command == 'run':
run(**dict_args)

elif args.command == 'n2j':
nrl2json(**dict_args)
23 changes: 23 additions & 0 deletions dptb/entrypoints/nrl2json.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from typing import Dict, List, Optional, Any
import ase.io as io
from pathlib import Path
from dptb.utils.read_NRL_tojson import read_nrl_file, nrl2dptb, save2json
import os
import logging
log = logging.getLogger(__name__)

def nrl2json(
INPUT: str,
nrl_file: str,
outdir: str,
log_level: int,
log_path: Optional[str],
**kwargs
):

NRL_data = read_nrl_file(nrl_file)
input_dict, nrl_tb_dict = nrl2dptb(INPUT, NRL_data)
save2json(input_dict, nrl_tb_dict, outdir)
log.info(f'NRL file {nrl_file} has been converted to {outdir}/nrl_ckpt.json.')
log.info(f'INPUT json is updated to {outdir}/input_nrl_auto.json.')
log.info('Please check the json file and modify the parameters if necessary.')
25 changes: 17 additions & 8 deletions dptb/nnsktb/formula.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import torch as th
from abc import ABC, abstractmethod
from dptb.nnsktb.bondlengthDB import bond_length

import re

class BaseSK(ABC):
def __init__(self) -> None:
Expand Down Expand Up @@ -35,15 +35,14 @@ def __init__(self, functype='varTang96',overlap=False) -> None:
self.num_paras = 2
assert hasattr(self, 'powerlaw')

elif functype == 'NRL':
elif re.search("NRL",functype):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这边原来"=="会出啥问题嘛

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

你应该也看到了,我为了兼容两种版本的NRL, 在input json里面指定模式的时候,NRLv0 和NRLv1 两种字段。这样的改成正则的判断是否是NRL就可以兼容这两种。最小变动。

self.functype = functype
self.num_paras = 4
assert hasattr(self, 'NRL_HOP')
if overlap:
self.overlap_num_paras = 4
assert hasattr(self, 'NRL_OVERLAP')


elif functype =='custom':
# the functype custom, is for user to define their own formula.
# just modify custom to the name of your formula.
Expand All @@ -68,7 +67,7 @@ def skhij(self, rij, **kwargs):
return self.varTang96(rij=rij, **kwargs)
elif self.functype == 'powerlaw':
return self.powerlaw(rij=rij, **kwargs)
elif self.functype == 'NRL':
elif re.search("NRL",self.functype):
return self.NRL_HOP(rij=rij, **kwargs)
else:
raise ValueError('No such formula')
Expand All @@ -83,8 +82,13 @@ def sksij(self,rij,**kwargs):
'''
assert self.overlap, 'overlap is False, no overlap function is defined.'

if self.functype == 'NRL':
return self.NRL_OVERLAP(rij=rij, **kwargs)
if self.functype == 'NRLv0':
return self.NRL_OVERLAP(rij=rij,overlap_type=0, **kwargs)
elif self.functype == 'NRLv1':
return self.NRL_OVERLAP(rij=rij,overlap_type=1, **kwargs)
elif self.functype == "NRL":
# default is designed for overlap type 1.
return self.NRL_OVERLAP(rij=rij,overlap_type=1, **kwargs)
else:
raise ValueError('No such formula')

Expand Down Expand Up @@ -146,7 +150,7 @@ def NRL_HOP(self, rij, paraArray, rcut:th.float32 = th.tensor(6), w:th.float32 =

return (a + b * rij + c * rij**2) * th.exp(-d**2 * rij)*f_rij

def NRL_OVERLAP(self, rij, paraArray, paraconst, rcut:th.float32 = th.tensor(6), w:th.float32 = 0.1, **kwargs):
def NRL_OVERLAP(self, rij, paraArray, paraconst, rcut:th.float32 = th.tensor(6), w:th.float32 = 0.1, overlap_type=1, **kwargs):
"""
This function calculates the Overlap value of the form of NRL-TB

Expand Down Expand Up @@ -175,4 +179,9 @@ def NRL_OVERLAP(self, rij, paraArray, paraconst, rcut:th.float32 = th.tensor(6),
f_rij = 1/(1+th.exp((rij-rcut+5*w)/w))
f_rij[rij>=rcut] = 0.0

return (delta_ll + a * rij + b * rij**2 + c * rij**3) * th.exp(-d**2 * rij)*f_rij
if overlap_type==1:
return (delta_ll + a * rij + b * rij**2 + c * rij**3) * th.exp(-d**2 * rij)*f_rij
elif overlap_type ==0:
return (a + b * rij + c * rij**2) * th.exp(-d**2 * rij)*f_rij
else:
raise ValueError('No such overlap type')
4 changes: 2 additions & 2 deletions dptb/nnsktb/integralFunc.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from dptb.nnsktb.formula import SKFormula
from dptb.utils.index_mapping import Index_Mapings
from dptb.nnsktb.skintTypes import all_skint_types, all_onsite_intgrl_types, NRL_skint_type_constants

import re

# define the function for output all the hoppongs for given i,j.

Expand All @@ -20,7 +20,7 @@ def __init__(self, proj_atom_anglr_m, atomtype=None, mode='hopping', functype='v
self.bond_index_dict = sk_bond_ind_dict
self.para_Consts = None

if functype == 'NRL':
if re.search("NRL",functype):
self.para_Consts = NRL_skint_type_constants(reducted_skint_types)
# call to get the para constants!
# special onsite mode for strain, which use same sk strategy as hopping.
Expand Down
104 changes: 104 additions & 0 deletions dptb/tests/data/nrl/Cu.par
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
NN00000 (Old style Overlap Parameters)
Copper (Cu)
1 (One atom type in this file)
16.5 0.5 (RCUT and SCREENL for 1-1 interactions)
9 (Orbitals for atom 1)
63.54 (Atomic Weight of Atom 1)
1.0 0.0 10.0 (formal spd valence occupancy for atom 1)
1.47291793797E+00 0 1 lambda (equation 7)
2.13397883099E-02 0 2 a_s (equation 9)
6.93938937933E+01 0 3 b_s (equation 9)
-2.44786970765E+03 0 4 c_s (equation 9)
0.00000000000E+00 1 5 d_s (equation 9)
5.55994187020E-01 0 6 a_p (equation 9)
4.82151716250E+01 0 7 b_p (equation 9)
-3.82848296416E+02 0 8 c_p (equation 9)
0.00000000000E+00 1 9 d_p (equation 9)
1.99140354046E-02 0 10 a_t2g (equation 9)
3.46551434776E-01 0 11 b_t2g (equation 9)
8.08262913966E+01 0 12 c_t2g (equation 9)
0.00000000000E+00 1 13 d_t2g (equation 9)
1.99140354046E-02 0 14 a_eg (equation 9)
3.46551434776E-01 0 15 b_eg (equation 9)
8.08262913966E+01 0 16 c_eg (equation 9)
0.00000000000E+00 1 17 d_eg (equation 9)
-9.10328414400E+00 0 18 e_{ss sigma} (equation 11) (Hamiltonian)
5.17873222758E-01 0 19 f_{ss sigma} (equation 11) (Hamiltonian)
0.00000000000E+00 1 20 fbar_{ss sigma} (equation 11) (Hamiltonian)
9.46662011248E-01 0 21 g_{ss sigma} (equation 11) (Hamiltonian)
3.10062713161E+00 0 22 e_{sp sigma} (equation 11) (Hamiltonian)
-1.14986950324E-01 0 23 f_{sp sigma} (equation 11) (Hamiltonian)
0.00000000000E+00 1 24 fbar_{sp sigma} (equation 11) (Hamiltonian)
8.16823694041E-01 0 25 g_{sp sigma} (equation 11) (Hamiltonian)
1.08944420501E+00 0 26 e_{pp sigma} (equation 11) (Hamiltonian)
8.81042934823E-02 0 27 f_{pp sigma} (equation 11) (Hamiltonian)
0.00000000000E+00 1 28 fbar_{pp sigma} (equation 11) (Hamiltonian)
7.44047706326E-01 0 29 g_{pp sigma} (equation 11) (Hamiltonian)
-3.47450944858E+00 0 30 e_{pp pi} (equation 11) (Hamiltonian)
4.87501025402E-01 0 31 f_{pp pi} (equation 11) (Hamiltonian)
0.00000000000E+00 1 32 fbar_{pp pi} (equation 11) (Hamiltonian)
8.54244679374E-01 0 33 g_{pp pi} (equation 11) (Hamiltonian)
-2.32021648963E+00 0 34 e_{sd sigma} (equation 11) (Hamiltonian)
-3.15365861097E-02 0 35 f_{sd sigma} (equation 11) (Hamiltonian)
0.00000000000E+00 1 36 fbar_{sd sigma} (equation 11) (Hamiltonian)
9.25016281342E-01 0 37 g_{sd sigma} (equation 11) (Hamiltonian)
-8.93441918651E-01 0 38 e_{pd sigma} (equation 11) (Hamiltonian)
6.29552973893E-02 0 39 f_{pd sigma} (equation 11) (Hamiltonian)
0.00000000000E+00 1 40 fbar_{pd sigma} (equation 11) (Hamiltonian)
7.37891092773E-01 0 41 g_{pd sigma} (equation 11) (Hamiltonian)
-5.40576594803E+00 0 42 e_{pd pi} (equation 11) (Hamiltonian)
2.97343282536E+00 0 43 f_{pd pi} (equation 11) (Hamiltonian)
0.00000000000E+00 1 44 fbar_{pd pi} (equation 11) (Hamiltonian)
1.11838057144E+00 0 45 g_{pd pi} (equation 11) (Hamiltonian)
-1.76353510091E+00 0 46 e_{dd sigma} (equation 11) (Hamiltonian)
1.19111234449E-01 0 47 f_{dd sigma} (equation 11) (Hamiltonian)
0.00000000000E+00 1 48 fbar_{dd sigma} (equation 11) (Hamiltonian)
8.86269873950E-01 0 49 g_{dd sigma} (equation 11) (Hamiltonian)
4.33011070171E+00 0 50 e_{dd pi} (equation 11) (Hamiltonian)
1.60095701629E-01 0 51 f_{dd pi} (equation 11) (Hamiltonian)
0.00000000000E+00 1 52 fbar_{dd pi} (equation 11) (Hamiltonian)
1.08523543274E+00 0 53 g_{dd pi} (equation 11) (Hamiltonian)
8.61842136416E+00 0 54 e_{dd delta} (equation 11) (Hamiltonian)
-3.97339261135E+00 0 55 f_{dd delta} (equation 11) (Hamiltonian)
0.00000000000E+00 1 56 fbar_{dd delta} (equation 11) (Hamiltonian)
1.29257807974E+00 0 57 g_{dd delta} (equation 11) (Hamiltonian)
-4.62972771140E+00 0 58 e_{ss sigma} (equation 11) (Overlap)
9.47334015518E+00 0 59 f_{ss sigma} (equation 11) (Overlap)
0.00000000000E+00 1 60 fbar_{ss sigma} (equation 11) (Overlap)
1.14594187503E+00 0 61 g_{ss sigma} (equation 11) (Overlap)
-7.76506172706E+00 0 62 e_{sp sigma} (equation 11) (Overlap)
-7.02630525419E-01 0 63 f_{sp sigma} (equation 11) (Overlap)
0.00000000000E+00 1 64 fbar_{sp sigma} (equation 11) (Overlap)
9.74542956783E-01 0 65 g_{sp sigma} (equation 11) (Overlap)
-8.67145638940E-01 0 66 e_{pp sigma} (equation 11) (Overlap)
2.08503648647E-03 0 67 f_{pp sigma} (equation 11) (Overlap)
0.00000000000E+00 1 68 fbar_{pp sigma} (equation 11) (Overlap)
6.06850104373E-01 0 69 g_{pp sigma} (equation 11) (Overlap)
4.59109295666E-02 0 70 e_{pp pi} (equation 11) (Overlap)
5.34381165673E-02 0 71 f_{pp pi} (equation 11) (Overlap)
0.00000000000E+00 1 72 fbar_{pp pi} (equation 11) (Overlap)
6.65480180637E-01 0 73 g_{pp pi} (equation 11) (Overlap)
6.33227165093E+00 0 74 e_{sd sigma} (equation 11) (Overlap)
1.08482522687E+00 0 75 f_{sd sigma} (equation 11) (Overlap)
0.00000000000E+00 1 76 fbar_{sd sigma} (equation 11) (Overlap)
1.12243836659E+00 0 77 g_{sd sigma} (equation 11) (Overlap)
-3.61229839778E+00 0 78 e_{pd sigma} (equation 11) (Overlap)
2.03039543811E-01 0 79 f_{pd sigma} (equation 11) (Overlap)
0.00000000000E+00 1 80 fbar_{pd sigma} (equation 11) (Overlap)
9.56355983487E-01 0 81 g_{pd sigma} (equation 11) (Overlap)
-3.42670301782E+02 0 82 e_{pd pi} (equation 11) (Overlap)
-5.22754450519E+01 0 83 f_{pd pi} (equation 11) (Overlap)
0.00000000000E+00 1 84 fbar_{pd pi} (equation 11) (Overlap)
1.51831050681E+00 0 85 g_{pd pi} (equation 11) (Overlap)
-1.72505694381E+03 0 86 e_{dd sigma} (equation 11) (Overlap)
4.47319803867E+02 0 87 f_{dd sigma} (equation 11) (Overlap)
0.00000000000E+00 1 88 fbar_{dd sigma} (equation 11) (Overlap)
1.53712769046E+00 0 89 g_{dd sigma} (equation 11) (Overlap)
-6.49992657214E-01 0 90 e_{dd pi} (equation 11) (Overlap)
-3.47252277946E-01 0 91 f_{dd pi} (equation 11) (Overlap)
0.00000000000E+00 1 92 fbar_{dd pi} (equation 11) (Overlap)
1.08398267722E+00 0 93 g_{dd pi} (equation 11) (Overlap)
2.17111542861E+01 0 94 e_{dd delta} (equation 11) (Overlap)
-4.38355657085E+00 0 95 f_{dd delta} (equation 11) (Overlap)
0.00000000000E+00 1 96 fbar_{dd delta} (equation 11) (Overlap)
1.18724223365E+00 0 97 g_{dd delta} (equation 11) (Overlap)
Loading