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

feat(loss): add new loss options to control number bands to exclude in in dft bands. #181

Merged
merged 1 commit into from
Jun 5, 2024
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
13 changes: 13 additions & 0 deletions dptb/nnops/loss.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ def __init__(
diff_on: bool=False,
eout_weight: float=0.01,
diff_weight: float=0.01,
diff_valence: dict=None,
spin_deg: int = 2,
dtype: Union[str, torch.dtype] = torch.float32,
device: Union[str, torch.device] = torch.device("cpu"),
**kwargs,
Expand All @@ -94,6 +96,8 @@ def __init__(
self.diff_on = diff_on
self.eout_weight = eout_weight
self.diff_weight = diff_weight
self.diff_valence = diff_valence
self.spin_deg = spin_deg

if basis is not None:
self.idp = OrbitalMapper(basis, method="e3tb", device=self.device)
Expand Down Expand Up @@ -157,6 +161,15 @@ def forward(
eig_pred = data[AtomicDataDict.ENERGY_EIGENVALUE_KEY][0] # (n_kpt, n_band)
eig_label = ref_data[AtomicDataDict.ENERGY_EIGENVALUE_KEY][0] # (n_kpt, n_band_dft/n_band)

if self.diff_valence is not None and isinstance(self.diff_valence, dict):
nbands_exclude = sum([self.diff_valence[self.idp.type_to_chemical_symbol[int(ii)]] for ii in ref_data['atom_types']])
assert nbands_exclude % self.spin_deg == 0
nbands_exclude = nbands_exclude // self.spin_deg
else:
nbands_exclude = 0

eig_label = eig_label[:,nbands_exclude:]

norbs = eig_pred.shape[-1]
nbanddft = eig_label.shape[-1]
num_kp = eig_label.shape[-2]
Expand Down
2 changes: 2 additions & 0 deletions dptb/utils/argcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,8 @@ def loss_options():
Argument("diff_on", bool, optional=True, default=False, doc="Whether to use random differences in loss function. Default: False"),
Argument("eout_weight", float, optional=True, default=0.01, doc="The weight of eigenvalue out of range. Default: 0.01"),
Argument("diff_weight", float, optional=True, default=0.01, doc="The weight of eigenvalue difference. Default: 0.01"),
Argument("diff_valence", [dict,None], optional=True, default=None, doc="set the difference of the number of valence electrons in DFT and TB. eg {'A':6,'B':7}, Default: None, which means no difference"),
Argument("spin_deg", int, optional=True, default=2, doc="The spin degeneracy of band structure. Default: 2"),
]

skints = [
Expand Down
2 changes: 2 additions & 0 deletions dptb/utils/config_sk.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
"loss_options": {
"train": {
"method": "eigvals",
"diff_valence":None,
"spin_deg":2,
"diff_on": False,
"eout_weight": 0.01,
"diff_weight": 0.01
Expand Down