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

to_cube function has a bug #2817

Closed
giovannipizzi opened this issue Jan 26, 2023 · 1 comment · Fixed by #2909
Closed

to_cube function has a bug #2817

giovannipizzi opened this issue Jan 26, 2023 · 1 comment · Fixed by #2909
Labels
bug io Input/output functionality

Comments

@giovannipizzi
Copy link

Describe the bug
The to_cube function of VolumetricData has a bug: it stores in lines 4-6 the real-space vectors instead of the size of a voxel.

To Reproduce

  1. Get any cube file
  2. run the following code, that should return the same file (apart from cosmetics):
    from pymatgen.io.common import VolumetricData
    cubefile = VolumetricData.from_cube(IN_FNAME)
    cubefile.to_cube(OUT_FNAME)
  3. check the content of the two files. You will see that lines 4-6 are wrong.

E.g. in my case, original file (lines 4-6):

   72    0.170589    0.000000    0.000000
   80    0.000000    0.163473    0.000000
  108   -0.114105    0.000000    0.125017

Output file:

	 72 12.282408 0.000000 0.000000 
	 80 0.000000 13.077840 0.000000 
	 108 -12.323340 0.000000 13.501836 

Expected behavior
The correct values are written in the cube file.

It should be as simple as changing the following lines:

f"\t {self.dim[0]} "
f"{self.structure.lattice.matrix[0][0] * ang_to_bohr :.6f} "
f"{self.structure.lattice.matrix[0][1] * ang_to_bohr :.6f} "
f"{self.structure.lattice.matrix[0][2] * ang_to_bohr :.6f} \n"
)
file.write(
f"\t {self.dim[1]} "
f"{self.structure.lattice.matrix[1][0] * ang_to_bohr :.6f} "
f"{self.structure.lattice.matrix[1][1] * ang_to_bohr :.6f} "
f"{self.structure.lattice.matrix[1][2] * ang_to_bohr :.6f} \n"
)
file.write(
f"\t {self.dim[2]} "
f"{self.structure.lattice.matrix[2][0] * ang_to_bohr :.6f} "
f"{self.structure.lattice.matrix[2][1] * ang_to_bohr :.6f} "
f"{self.structure.lattice.matrix[2][2] * ang_to_bohr :.6f} \n"
)

to something like (untested, but should work)

            file.write(
                f"\t {self.dim[0]} "
                f"{self.structure.lattice.matrix[0][0] / self.dim[0] * ang_to_bohr :.6f} "
                f"{self.structure.lattice.matrix[0][1] / self.dim[0] * ang_to_bohr :.6f} "
                f"{self.structure.lattice.matrix[0][2] / self.dim[0] * ang_to_bohr :.6f} \n"
            )

and analogously for the following two lines.

@janosh
Copy link
Member

janosh commented Mar 24, 2023

Thanks for reporting! 👍

@janosh janosh added bug io Input/output functionality labels Mar 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug io Input/output functionality
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants