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

Generate automatic lattice vectors in loadGeometry #216

Merged
merged 4 commits into from
Oct 26, 2023

Conversation

mondracek
Copy link
Collaborator

Fixes #52
Supersedes #213 and #197

…ini nor the input file specify them

Moreover
- remove premature call to autoGridN in loadParams
- enable reading ASE-style lattice vector from XYZ in ppafm_gui.py
- handle fzs/Fout deletion in plot_results.py correctly depending on tip tilt
- correct typo Lenard-Jones -> Lennard-Jones
- add 'self' argument to prepareFEConv() in relax.py to console precommit checks
- resolve conflicts in formatting resulting from limits on line length

Set grid in computeELFF_pointCharge before parsing atoms

Correct swapped PBC / not PBC condition in loadGeometry

Correct format of atomic data returned by loadGeometry
- accept the solution from branch load-geometry-fix by Niko Oinonen
- read 'nDim' from 'gridN' for POSCAR and geometry.in inputs

Repair a comment line in io.py broken by automatic reformatting

Repair an indentation error in ppafm/HighLevel.py and typo in ppafm/cpp/Force.h
@mondracek mondracek requested a review from NikoOinonen October 24, 2023 12:57
@mondracek
Copy link
Collaborator Author

The formatting changes were removed with the help of @yakutovicha and the other commits squashed into one.

ppafm/io.py Outdated Show resolved Hide resolved
ppafm/io.py Outdated Show resolved Hide resolved
@mondracek
Copy link
Collaborator Author

mondracek commented Oct 25, 2023

@NikoOinonen , I implemented the amendments you proposed (not pushed yet). Restricting the automatic cell to the scan region (plus some padding) works okay for non-periodic structures. It leads to wrong results for PBC True in params.ini. That would not be a problem since the automatically generated cell is intended for clusters and isolated molecules while for periodic structures, the lattice vectors should be given explicitly. However, it may become a problem because params["PBC"]=True is our default now. I have already proposed to make PBC False the default in the discussion under #52 but forgot about it later.

What I'd proposed now: Make params["PBC"]=None by default and unless PBC True or PBC False is specified explicitly in params.ini, make it True when reading the input from *.xsf or from geometry.in without lattice_vectors, and make it False when reading from the *.xyz file or a geometry.in file without lattice_vectors. I am not sure about *.cube files, whether they should change params["PBC"]=None to params["PBC"]=True or to params["PBC"]=False. Probably to False as the CUBE format is originally intended for non-periodic systems although FHI-AIMS often uses it for periodic ones too. As for the XSF format, it could actually describe a non-periodic system too, but we are currently not making the distinction. Should I implement this default handling of PBC in this PR?

@NikoOinonen
Copy link
Collaborator

What I'd proposed now: Make params["PBC"]=None by default and unless PBC True or PBC False is specified explicitly in params.ini

Yes, it makes sense to have some default behaviour when not otherwise specified.

make it True when reading the input from *.xsf or from geometry.in with lattice_vectors, and make it False when reading from the *.xyz file or a geometry.in file without lattice_vectors. I am not sure about *.cube files, whether they should change params["PBC"]=None to params["PBC"]=True or to params["PBC"]=False.

Would it not be fine to just set it True whenever the lattice vectors are defined in the input regardless of the format (when not explicitly set as False)? Especially for cube files (and for xsf), the convolution of the Hartree potential is always periodic just because of how the operation is defined, so we end up using periodic boundary conditions anyways.

Should I implement this default handling of PBC in this PR?

Yes, I think it makes sense, since it affects the behaviour here.

@mondracek
Copy link
Collaborator Author

Right, I was about to do it that way after all: Set params["PBC"] in loadGeometry depending on whether the lvec is None or something else. However, I realized we must not initialize params["PBC"] as None in common.py as I tried to do. The type of each parameter is determined by its initial value and when it is unknown, reading the parameter from params.ini does not work. So I will have to leave the default value of params["PBC"] to be True. But then, I must not force it to be False even if e.g. the input is a *xyz file without lattice vectors because the lattice vectors can still be specified as the gridA, gridB, gridC parameters in params.ini and the user can mean these as true lattice vectors rather than just dimensions of a non-periodic grid.
So in the end, the only thing I can do with params["PBC"] in response to the geometry read from the input is to put params["PBC"]=False exactly when the automatic grid is being generated and leave it as it was (set by default or by the user in params.ini) otherwise.

- Sets PBC to False whenever automatic grid needs to be created
- Remove the back-and-forth transformation between pivot-particle and probe-particle coordinates
@mondracek
Copy link
Collaborator Author

Pushed a new version that reflects the recent discussion.

ppafm/io.py Outdated Show resolved Hide resolved
ppafm/io.py Outdated Show resolved Hide resolved
ppafm/io.py Outdated
Comment on lines 452 to 454
if np.allclose(lvec[i + 1, :], 0):
params["PBC"] = False
lvec[i + 1, i] = probeMax[i] + pad
Copy link
Collaborator

Choose a reason for hiding this comment

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

It seems to me like we are not taking into account the start of the scan region here. I think we would need to adjust the origin of the lvec to be at something like probeMin - pad, and then the length of the lattice vectors would be something like probeMax - probeMin + 2 * pad? Notice that currently probeMin is not used.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Exactly right. The thing is, the current version of the code (at least the CPU part, I do not know about the OCL) does not work with non-zero origin in non-periodic systems. I should and I will solve this, but as a separate issue. In fact, I have added a line #lvec[i + 1, i] = probe_max[i] - probe_min[i] + 2*pad to io.py, which is commented-out for now but which I intend to use instead of the contemporary lvec[i + 1, i] = probe_max[i] + pad as soon as I solve the issue of an arbitrary origin.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ok, I didn't know that. It should work with any origin in the OCL code. I guess this by extension means that negative scan window coordinates don't work when PBC = False. Is there an issue for this? If not, then better make one so that it does not slip by.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Exactly, last time I tried I got a blank area with zero forces for the part of scan region in which any of the three coordinates negative. There is no issue about it and I am going to make one. The original plan was to solve it as a by-product of #217 (may seem to be unrelated but as FHI-AIMS tends to be creative about the grid origin, it would have to be done to address that issue too). However, as I am being rather discouraged to implement #217, I will start a separate issue.

@@ -451,7 +451,8 @@ def loadGeometry(fname=None,format=None,params=None):
# The automatic generated lattice vector should enclose the whole area filled with atoms as well as the whole scanning area, plus the default padding.
if np.allclose(lvec[i + 1, :], 0):
params["PBC"] = False
lvec[i + 1, i] = probeMax[i] + pad
#lvec[i + 1, i] = probe_max[i] - probe_min[i] + 2*pad
Copy link
Collaborator Author

@mondracek mondracek Oct 26, 2023

Choose a reason for hiding this comment

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

This comment line will be activated once we deal with a potentially non-zero origin properly.

Copy link
Collaborator

@NikoOinonen NikoOinonen left a comment

Choose a reason for hiding this comment

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

Ok, looks good now. Thanks Martin!

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.

Handling missing lattice vectors
2 participants