Skip to content

Commit 3202d05

Browse files
committed
feat(dftb): add output directory support for SK table generation
Add output directory parameter to DFT2SKTable constructor and implement file path handling. This allows specifying where generated SK tables should be saved, creating the directory if it doesn't exist.
1 parent 973dae8 commit 3202d05

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

dptb/nn/dftb/atomicdft.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@
1313
from dptb.nn.sktb.builtin_skbasisDB import skbasisDB
1414
from dptb.nn.sktb.builtin_skbasisDB import onsite_e_builtin_basis, occupations_builtin_basis, Hubbard_U_builtin_basis
1515
import logging
16+
import os
1617
log = logging.getLogger(__name__)
1718

1819

1920
class DFT2SKTable(object):
20-
def __init__(self, xc: str, superposition: str = 'density', scalarrel=True, **kwargs):
21+
def __init__(self, xc: str, superposition: str = 'density', scalarrel:bool=True, output:str='./', **kwargs):
2122
'''This Python function initializes parameters for XC functional calculations, allowing for
2223
customization of the functional, superposition scheme, and scalar relativistic corrections.
2324
@@ -43,7 +44,10 @@ def __init__(self, xc: str, superposition: str = 'density', scalarrel=True, **kw
4344
self.scalarrel = scalarrel
4445
self.kwargs = kwargs
4546
self.atomic_objs = {}
46-
47+
if not os.path.exists(output):
48+
os.makedirs(output)
49+
self.output = output
50+
self.out_filename_template = output + '/{el1}-{el2}.skf'
4751
def update_config(self, basis:Dict[str, List], rw: dict, pw:dict, rd:dict=None, pd:dict=None):
4852
atomic_symbols = list(basis.keys())
4953
# check basis
@@ -133,15 +137,16 @@ def get_skf_pair(self, atom_a:str, atom_b:str=None, rmin=0.4, dr=0.02, N = 800,
133137
# Write the SK tables without repulsion (only electronic part)
134138
# for homo-case, the atomic eigenvalues, Hubbardvalues, occupations are also saved
135139
# but the spe as well as the (spin-polarization error) is set to 0.0.
136-
140+
137141
if atom_a == atom_b:
138142
self.off2c.write(eigenvalues=self.atomic_objs[atom_a]['eigenvalues'],
139143
hubbardvalues=self.atomic_objs[atom_a]['hubbardvalues'],
140144
occupations=self.atomic_objs[atom_a]['occupations'],
141-
spe=0.
145+
spe=0.,
146+
filename_template=self.out_filename_template
142147
)
143148
else:
144-
self.off2c.write()
149+
self.off2c.write(filename_template=self.out_filename_template)
145150
log.info(f'finished writing sk tables....')
146151

147152
def get_full_pair(self, atom_a:str, atom_b:str=None, rmin=0.4, dr=0.02, N = 800, stride=1):

0 commit comments

Comments
 (0)