Queries about input and output files, running specific calculations, etc.
Moderators: Global Moderator, Moderator
-
hszhao.cn@gmail.com
- Full Member
- Posts: 189
- Joined: Tue Oct 13, 2020 11:32 pm
#16
Post
by hszhao.cn@gmail.com » Fri Apr 05, 2024 3:32 am
I want to find the mapping/transformation relationship between the Cartesian coordinates of all atoms of these two POSCARs, as shown below:
Code: Select all
In [14]: from pymatgen.io.vasp import Poscar
...:
...: # Reading the POSCAR files
...: poscar_ms = Poscar.from_file("POSCAR_ms")
...: poscar_vaspkit = Poscar.from_file("POSCAR_vaspkit")
...:
...: # Getting the Cartesian coordinates of all atoms in both structures
...: cart_coords_ms = poscar_ms.structure.cart_coords
...: cart_coords_vaspkit = poscar_vaspkit.structure.cart_coords
...:
...: # Printing the Cartesian coordinates of all atoms in the original structure (POSCAR_ms)
...: print("Cartesian coordinates of all atoms in the original structure (POSCAR_ms):")
...: for i, coords in enumerate(cart_coords_ms, start=1):
...: print(f"Atom {i}: {coords}")
...:
...: # Printing the Cartesian coordinates of all atoms in the target structure (POSCAR_vaspkit)
...: print("\nCartesian coordinates of all atoms in the target structure (POSCAR_vaspkit):")
...: for i, coords in enumerate(cart_coords_vaspkit, start=1):
...: print(f"Atom {i}: {coords}")
...:
Cartesian coordinates of all atoms in the original structure (POSCAR_ms):
Atom 1: [0. 0. 0.]
Atom 2: [1.93350005 1.11630678 0.78934807]
Cartesian coordinates of all atoms in the target structure (POSCAR_vaspkit):
Atom 1: [0. 0. 0.]
Atom 2: [1.36718202 1.36718202 1.36718202]
After some thought and trying, the problem still hasn't been solved.
-
hszhao.cn@gmail.com
- Full Member
- Posts: 189
- Joined: Tue Oct 13, 2020 11:32 pm
#17
Post
by hszhao.cn@gmail.com » Fri Apr 05, 2024 3:53 am
Then, my other question is: Find the mapping/transformation relationship between the Cartesian coordinates of all atoms of two POSCARs, as shown below:
Code: Select all
$ cat POSCAR_ms
Si2-primitive cell from MS software
1.0
3.8670001030 0.0000000000 0.0000000000
1.9335000515 3.3489203256 0.0000000000
1.9335000515 1.1163067752 3.1573923625
Si
2
Direct
0.000000000 0.000000000 0.000000000
0.250000002 0.250000005 0.249999992
$ cat POSCAR_vaspkit
Si2-primitive cell from VASPKIT software
1.000000
0.00000000000000 2.73436403275000 2.73436403275000
2.73436403275000 0.00000000000000 2.73436403275000
2.73436403275000 2.73436403275000 0.00000000000000
Si
2
DIRECT
0.0000000000000000 0.0000000000000000 0.0000000000000000 Si1
0.2500000000000000 0.2500000000000000 0.2500000000000000 Si2
The Cartesian coordinates of all atoms are shown below:
Code: Select all
In [14]: from pymatgen.io.vasp import Poscar
...:
...: # Reading the POSCAR files
...: poscar_ms = Poscar.from_file("POSCAR_ms")
...: poscar_vaspkit = Poscar.from_file("POSCAR_vaspkit")
...:
...: # Getting the Cartesian coordinates of all atoms in both structures
...: cart_coords_ms = poscar_ms.structure.cart_coords
...: cart_coords_vaspkit = poscar_vaspkit.structure.cart_coords
...:
...: # Printing the Cartesian coordinates of all atoms in the original structure (POSCAR_ms)
...: print("Cartesian coordinates of all atoms in the original structure (POSCAR_ms):")
...: for i, coords in enumerate(cart_coords_ms, start=1):
...: print(f"Atom {i}: {coords}")
...:
...: # Printing the Cartesian coordinates of all atoms in the target structure (POSCAR_vaspkit)
...: print("\nCartesian coordinates of all atoms in the target structure (POSCAR_vaspkit):")
...: for i, coords in enumerate(cart_coords_vaspkit, start=1):
...: print(f"Atom {i}: {coords}")
...:
Cartesian coordinates of all atoms in the original structure (POSCAR_ms):
Atom 1: [0. 0. 0.]
Atom 2: [1.93350005 1.11630678 0.78934807]
Cartesian coordinates of all atoms in the target structure (POSCAR_vaspkit):
Atom 1: [0. 0. 0.]
Atom 2: [1.36718202 1.36718202 1.36718202]
Then, how can I find the mapping/transformation relationship between the Cartesian coordinates of all atoms of these two structures?
Regards,
Zhao
-
martin.schlipf
- Global Moderator
- Posts: 542
- Joined: Fri Nov 08, 2019 7:18 am
#18
Post
by martin.schlipf » Fri Apr 05, 2024 6:53 am
I have added everything I know about this topic to this thread. Perhaps some user has additional input regarding this but I cannot offer any further advice.
Martin Schlipf
VASP developer
-
hszhao.cn@gmail.com
- Full Member
- Posts: 189
- Joined: Tue Oct 13, 2020 11:32 pm
#19
Post
by hszhao.cn@gmail.com » Fri Apr 05, 2024 9:39 am
Then, how can I find the mapping/transformation relationship between the Cartesian coordinates of all atoms of these two structures?
I got it, as shown below:
Code: Select all
In [79]: from pymatgen.core import Structure
...: from pymatgen.analysis.structure_matcher import StructureMatcher
...:
...: poscar1 = 'POSCAR_ms'
...: poscar2 = 'POSCAR_vaspkit'
...:
...: structure1 = Structure.from_file(poscar1)
...: structure2 = Structure.from_file(poscar2)
...:
...: matcher = StructureMatcher(primitive_cell=False)
...: matches = matcher.fit(structure1, structure2)
...:
...: if matches:
...: try:
...: transformation = matcher.get_transformation(structure1, structure2)
...: print(transformation)
...: except ValueError as e:
...: print(f"error:{str(e)}")
...: else:
...: print("Failed to match.")
...:
(array([[ 0, 0, -1],
[ 0, -1, 0],
[-1, 0, 0]]), array([0.25, 0.25, 0.25]), [1, 0])
In [80]: from numpy import array
...: from numpy.linalg import inv
...: from pymatgen.core import Structure
...: s1=Structure.from_file("POSCAR_ms")
...: s2=Structure.from_file("POSCAR_vaspkit")
...:
...: m1=s1.lattice.matrix
...: m2=s2.lattice.matrix
...:
...: R=transformation[0]
...: t=transformation[1]
...:
...: print(m2.T@(R@inv(m1.T)@array([0,0,0]) + t))
...: print(m2.T@(R@inv(m1.T)@array([1.93350005, 1.11630678, 0.78934807]) + t))
[1.36718201 1.36718201 1.36718203]
[-1.69082426e-08 6.72491127e-09 1.75588875e-08]
See
here for the related discussion.