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

Save Q vectors in the output file #634

Open
wants to merge 5 commits into
base: protos
Choose a base branch
from

Conversation

MBartkowiakSTFC
Copy link
Collaborator

@MBartkowiakSTFC MBartkowiakSTFC commented Jan 14, 2025

Description of work
The Q vectors used in MDANSE calculations are typically created using a generator based on a limited number of input parameters. To improve the transparency and reproducibility of the calculations, it is meaningful to save the information about the exact values of the q vectors that were used in each calculation.

closes #564

Fixes

  1. The calculation between HKL values and reciprocal space vectors has been standardised.
  2. The Q vector information is now saved in the output files of each analysis using Q vectors.
  3. DCSF calculation now uses average unit cell parameters to generate Q vectors. This should not change the results for NVT simulations, while it may slightly reduce the noise for the NPT simulations.

To test
Run a scattering analysis. Confirm that the q vectors have been written into the output files.
Use SphericalLatticeQVectors in a DCSF run on a trajectory with fixed simulation box dimensions. Check that the HKL values are all integer numbers.

@ChiCheng45
Copy link
Collaborator

I get a job failure when running DCSF with SphericalQVectors. However, I'm wondering whether or not the user should be able to choose this qvector generator for DCSF.

Also, I think we need to decide on what our stance on NPT simulations should be. This was brought up some time ago in #213 which mentions the issue for MSD and related jobs but there will be issues with the qvector generation which we try to fix here with the averaged unit cell. I'm wondering if we should follow dynasor (https://dynasor.materialsmodeling.org/workflow.html#limitations) and only allow for constant-volume MD simulations.

@gonzalezma
Copy link
Collaborator

I think that choosing to treat only constant-volume simulations is a valid decision, especially if we decide that we cannot handle volume changes fully correctly. Perhaps it could be useful to do a small internal survey at ISIS and the ILL and ask some of our known users if they ever analyse NPT trajectories. My guess is that allowing only for constant-V simulations is probably not a big loss.

output_data : OutputData
An object managing the writeout to one or many output files
"""
q_values = [float(x) for x in self._configuration["q_vectors"].keys()]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Keys is redundant.

Suggested change
q_values = [float(x) for x in self._configuration["q_vectors"].keys()]
q_values = [float(x) for x in self._configuration["q_vectors"]]

Comment on lines +61 to +63
int(2 * hklMax[0, 0] + 1)
* int(2 * hklMax[1, 1] + 1)
* int(2 * hklMax[2, 2] + 1),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
int(2 * hklMax[0, 0] + 1)
* int(2 * hklMax[1, 1] + 1)
* int(2 * hklMax[2, 2] + 1),
np.prod(2 * np.diag(hklMax) + 1, dtype=int),

original_qvectors = instance._configuration["q_vectors"][q]["q_vectors"]
except KeyError:
continue
print("q_vectors", original_qvectors)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Leftover prints?

Comment on lines +92 to +93
self._axes["index" + str(dim_number)] = np.arange(dim_length)
self._axes_units["index" + str(dim_number)] = "N/A"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
self._axes["index" + str(dim_number)] = np.arange(dim_length)
self._axes_units["index" + str(dim_number)] = "N/A"
self._axes[f"index{dim_number}"] = np.arange(dim_length)
self._axes_units[f"index{dim_number}"] = "N/A"

units="1/nm",
)
qvector_lengths = [
self._configuration["q_vectors"][q]["q_vectors"].shape[1] for q in q_values
Copy link
Collaborator

Choose a reason for hiding this comment

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

Given you refer to self._configuration["q_vectors"] a lot, would recommend adding

qvec_info = self._configuration["q_vectors"]

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.

[ENHANCEMENT] Save the some information about the q-vectors that were generated.
4 participants