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

fix: idp(data) in nnsk and deeptb, and refactor soc switch in hr2hk #152

Merged
merged 1 commit into from
Apr 29, 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
6 changes: 6 additions & 0 deletions dptb/nn/deeptb.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,8 @@ def __init__(


def forward(self, data: AtomicDataDict.Type):
if data.get(AtomicDataDict.EDGE_TYPE_KEY, None) is None:
self.idp(data)

data = self.embedding(data)
if hasattr(self, "overlap"):
Expand Down Expand Up @@ -368,6 +370,10 @@ def __init__(


def forward(self, data: AtomicDataDict.Type):

if data.get(AtomicDataDict.EDGE_TYPE_KEY, None) is None:
self.idp(data)

data_nnenv = self.nnenv(data)
if hasattr(self, "nnsk"):
data_sk = self.nnsk(data)
Expand Down
10 changes: 6 additions & 4 deletions dptb/nn/hr2hk.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ def forward(self, data: AtomicDataDict.Type) -> AtomicDataDict.Type:
bondwise_hopping.type(self.dtype)
onsite_block = torch.zeros((len(data[AtomicDataDict.ATOM_TYPE_KEY]), self.idp.full_basis_norb, self.idp.full_basis_norb,), dtype=self.dtype, device=self.device)


if data[AtomicDataDict.NODE_SOC_SWITCH_KEY].all():
soc = data.get(AtomicDataDict.NODE_SOC_SWITCH_KEY, False)
if isinstance(soc, torch.Tensor):
soc = soc.all()
if soc:
if self.overlap:
raise NotImplementedError("Overlap is not implemented for SOC.")

Expand Down Expand Up @@ -92,7 +94,7 @@ def forward(self, data: AtomicDataDict.Type) -> AtomicDataDict.Type:
if i <= j:
onsite_block[:,ist:ist+2*li+1,jst:jst+2*lj+1] = factor * orbpair_onsite[:,self.idp.orbpair_maps[orbpair]].reshape(-1, 2*li+1, 2*lj+1)

if data[AtomicDataDict.NODE_SOC_SWITCH_KEY].all() and i==j:
if soc and i==j:
soc_updn_tmp = orbpair_soc[:,self.idp.orbpair_soc_maps[orbpair]].reshape(-1, 2*li+1, 2*(2*lj+1))
soc_upup_block[:,ist:ist+2*li+1,jst:jst+2*lj+1] = soc_updn_tmp[:, :2*li+1,:2*lj+1]
soc_updn_block[:,ist:ist+2*li+1,jst:jst+2*lj+1] = soc_updn_tmp[:, :2*li+1,2*lj+1:]
Expand Down Expand Up @@ -150,7 +152,7 @@ def forward(self, data: AtomicDataDict.Type) -> AtomicDataDict.Type:
block = block + block.transpose(1,2).conj()
block = block.contiguous()

if data[AtomicDataDict.NODE_SOC_SWITCH_KEY].all():
if soc:
HK_SOC = torch.zeros(data[AtomicDataDict.KPOINT_KEY].shape[0], 2*all_norb, 2*all_norb, dtype=self.ctype, device=self.device)
#HK_SOC[:,:all_norb,:all_norb] = block + block_uu
#HK_SOC[:,:all_norb,all_norb:] = block_ud
Expand Down
2 changes: 2 additions & 0 deletions dptb/nn/nnsk.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,8 @@ def forward(self, data: AtomicDataDict.Type) -> AtomicDataDict.Type:


data = AtomicDataDict.with_edge_vectors(data, with_lengths=True)
if data.get(AtomicDataDict.EDGE_TYPE_KEY, None) is None:
self.idp_sk(data)

# edge_number = data[AtomicDataDict.ATOMIC_NUMBERS_KEY][data[AtomicDataDict.EDGE_INDEX_KEY]].reshape(2, -1)
# edge_index = self.idp_sk.transform_reduced_bond(*edge_number)
Expand Down