-
-
Notifications
You must be signed in to change notification settings - Fork 60
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
translate2uc
for sparse matrices with associated geometries.
#585
Conversation
One thing that I'm not sure how to do is to re-sort the column indices (that is, I don't know if there is already a method that does that). Because I modified them but I left them unsorted. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets start with the first method, and work from there.
src/sisl/sparse_geometry.py
Outdated
@@ -3006,6 +3006,108 @@ def assert_unique(old, new): | |||
out._csr = csr | |||
out._geometry = geom | |||
return out | |||
|
|||
def translate2uc(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably the interface should be equivalent to the Geometry.translate2uc
, it would also allow selection of atoms
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes 👍 This was just to make it as simple as possible for now so that the code was easier to review
src/sisl/sparse_geometry.py
Outdated
# should be moved to supercell (0,0,0). | ||
return self.translate_atoms_sc(-current_sc, geometry_coords=uc_fcoords @ self.cell) | ||
|
||
def translate_atoms_sc(self, sc_translations, geometry_coords=None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm... I don't particularly like this method. Couldn't we start with the translate2uc
with the atoms specification, and if there is a need for the translate_atoms_sc
then reconsider?
I see this method as being the equivalent of a translate
method, since the geometry_coords
can change the coords at will.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will remove the geometry_coords
argument, it was just to avoid recomputing the coordinates in the particular case of translate2uc
but now I see that it's exactly the same amount of computation whether I precompute or compute inside the method.
I can also make the method private for now. But I thought it was a nice separation of functionality since the only specificity of translate2uc
is to know how much unit cells is each atom translated. And since the translation of the matrix elements is not trivial to implement I figured it would be nice to keep it like this.
See now, you still don't like |
Codecov Report
@@ Coverage Diff @@
## main #585 +/- ##
==========================================
+ Coverage 87.28% 87.33% +0.05%
==========================================
Files 375 373 -2
Lines 47564 47676 +112
==========================================
+ Hits 41518 41640 +122
+ Misses 6046 6036 -10
|
I just checked that doing a Also I checked that the translation (even with the current perhaps naive implementation) is for free compared to the density computation. In my test system 35.5 ms versus 1.5min. |
translate2uc
for sparse matrices with associated geometries.translate2uc
for sparse matrices with associated geometries.
This is now fully functional, with tests that cover everything :) After you review I can squash everything into a single commit. |
Signed-off-by: Nick Papior <[email protected]>
@pfebrer could you have a look? I would think this is fine (made the |
Also, once in you should check that this works faster due to cb7e3cb |
Hold on, something is missing, a test for sparse orbital |
Signed-off-by: Nick Papior <[email protected]>
Looks good to me 👍 |
As discussed in #583, this PR creates a function that translates all atoms of a sparse matrix to the unit cell, updating both the coordinates and the indices of the matrix elements.
The current state of the code contains only the simplest possible behavior, implemented in the most straightforward way I could think of. And only for
SparseOrbital
, not yet forSparseAtom
. This is so that you can easily give it a look and see if there is some conceptual mistake. Also, I am aware that this is not the most time and memory efficient implementation possible, but I can optimize it later (suggestions accepted :)). Also I don't know what is the approppiate ratiooptimization/readability
for this.I thought about it, and I see no way of using the
translate_columns
without making the code more complex and unreadable, because the translation of each matrix element depends on both the columns and rows. So, a column translates differently depending on which row are we.Demo
I did a very simple test with a hydrogen molecule, which I generated like:
Then I ran a SIESTA calculation for this molecule as is and the same molecule with the first atom displaced one cell in X. I used
ForceAuxCell t
and defaults for the rest of inputs.I read the DMs and plot them:
Then, I translate the second DM to the unit cell:
All the heavy lifting is done by the
translate_atoms_sc
method, which receives the cell translations of all atoms. So you can displace the atoms differently and it also works. Here I displace the atom that was in the unit cell to the same cell as the displaced atom: