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

Reading spin densities from CHGCAR #754

Merged
merged 6 commits into from
Apr 22, 2024

Conversation

tfrederiksen
Copy link
Contributor

@tfrederiksen tfrederiksen commented Apr 22, 2024

The spin densities were not correctly read from CHGCAR, because after the augmentation occupancies an additional block of values (apparently one per atom) is found on file.

I could not determine what this extra block refers to, as it is not explicitly mentioned in the documentation from the VASP forum, which just mentions:

For magnetic calculations, the CHGCAR file contains additional data blocks for the magnetization. In particular, for spin-polarized calculations (ISPIN=2), the first set contains the total charge density (spin up + spin down) and the second one is the magnetization density (spin up - spin down):

  • Structure
  • FFT-grid dimensions
  • Charge density times FFT-grid volume (spin up + spin down)
  • Augmentation occupancies
  • FFT-grid dimensions
  • Magnetization density (spin up - spin down)
  • Augmentation occupancies

This PR resolves this issue and adds some further checks.

Copy link

codecov bot commented Apr 22, 2024

Codecov Report

Attention: Patch coverage is 96.42857% with 1 lines in your changes are missing coverage. Please review.

Project coverage is 86.78%. Comparing base (71360c5) to head (ff56451).

❗ Current head ff56451 differs from pull request most recent head ed7d651. Consider uploading reports for the commit ed7d651 to get more accurate results

Files Patch % Lines
src/sisl/io/vasp/chg.py 75.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #754   +/-   ##
=======================================
  Coverage   86.77%   86.78%           
=======================================
  Files         410      410           
  Lines       51785    51811   +26     
=======================================
+ Hits        44939    44965   +26     
  Misses       6846     6846           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Owner

@zerothi zerothi left a comment

Choose a reason for hiding this comment

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

Could we add a link to the documentation or something, so it is clear what the indices of grid values refers too?

# one line of nx, ny, nz
rl()
assert len(rl().split()) == 3
Copy link
Owner

Choose a reason for hiding this comment

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

perhaps do another assert that these values matches the nx, ny, nz, that would be great!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea! Will do.

@tfrederiksen
Copy link
Contributor Author

Could we add a link to the documentation or something, so it is clear what the indices of grid values refers too?

Where would you add a link? The docstring already describes the index and spin arguments, no?

@zerothi
Copy link
Owner

zerothi commented Apr 22, 2024

Could we add a link to the documentation or something, so it is clear what the indices of grid values refers too?

Where would you add a link? The docstring already describes the index and spin arguments, no?

It seems to me that line 35 is then wrong, no?

@tfrederiksen
Copy link
Contributor Author

It seems to me that line 35 is then wrong, no?

Oh, I see. Yes, indeed index=1 would give the spin density and not the down-component as currently stated. By the way, why two keywords index/spin for the same thing? Wouldn't it not be better to have just one?

@zerothi
Copy link
Owner

zerothi commented Apr 22, 2024

It seems to me that line 35 is then wrong, no?

Oh, I see. Yes, indeed index=1 would give the spin density and not the down-component as currently stated. By the way, why two keywords index/spin for the same thing? Wouldn't it not be better to have just one?

Yes, currently this is a left-over from the siesta output.
A think we could investigate is whether index should be used for explicit retrieval (no manipulation), and spin="x" could be used for explicit spin-configuration extraction, or spin=Spin.X.

Probably that should also be stream-lined.

@tfrederiksen
Copy link
Contributor Author

Yes, currently this is a left-over from the siesta output. A think we could investigate is whether index should be used for explicit retrieval (no manipulation), and spin="x" could be used for explicit spin-configuration extraction, or spin=Spin.X.

Probably that should also be stream-lined.

I've now updated the docstring and included some examples. I think the stream-lining could be a future PR.

tfrederiksen and others added 3 commits April 22, 2024 19:04
and added the down_density as well.

Signed-off-by: Nick Papior <[email protected]>
Signed-off-by: Nick Papior <[email protected]>
@zerothi zerothi merged commit f2d61b1 into zerothi:main Apr 22, 2024
6 checks passed
@tfrederiksen tfrederiksen deleted the vasp-chgcar-fix branch April 22, 2024 18:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants