-
Notifications
You must be signed in to change notification settings - Fork 2
SOF-7915: refactor espresso structure parser, support for non-zero ibrav #157
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
Open
pranabdas
wants to merge
20
commits into
main
Choose a base branch
from
refactor/SOF-7915
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
5df8e62
SOF-7915: refactor espresso structure parser to use pymatgen
pranabdas 9829d63
use qe-tools to parse structure from espresso-in
pranabdas 1a1177d
add tests for espresso-in parser
pranabdas 521ad33
merge main and resolve conflicts
pranabdas 9bac1b5
implement qe pw input parser using made
pranabdas e141f3c
fix made[tools] dependency
pranabdas 52a13cc
bump made
pranabdas 94555a9
use BOHR_TO_ANGSTROM contstant via utils
pranabdas a93bb05
replace strip_comments with remove_comments_from_source_code from mat…
pranabdas b019cab
refactor after moving parsers to parsers repo
pranabdas 9e2b20e
use updated parser to get_namelist
pranabdas e35f92d
merge main and resolve conflicts
pranabdas 7be6036
refactor parser changes
pranabdas 04c1f91
bump parser
pranabdas 13da531
bump parsers
pranabdas c8a5252
update parsers
pranabdas c0be228
update parsers
pranabdas 01565af
update parser class
pranabdas 59ea4b1
remove espresso comments by chaining fortran and python comments
pranabdas 26d8d61
chore: bump gh actions/checkout
pranabdas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| import math | ||
| from typing import List | ||
|
|
||
| from mat3ra.esse.models.properties_directory.structural.lattice import LatticeSchema | ||
| from mat3ra.made.cell.primitive_cell import get_primitive_lattice_vectors_from_config | ||
| from mat3ra.utils.constants import COEFFICIENTS | ||
| from mat3ra.utils.string import remove_comments_from_source_code | ||
| from mat3ra.parsers.applications.espresso.pw_x.stdin.parser import EspressoPwxStdinParser | ||
|
|
||
| # Maps QE ibrav codes → made/esse Bravais type strings | ||
| IBRAV_TO_LATTICE_TYPE = { | ||
| 1: "CUB", | ||
| 2: "FCC", | ||
| 3: "BCC", -3: "BCC", | ||
| 4: "HEX", | ||
| 5: "RHL", -5: "RHL", | ||
| 6: "TET", | ||
| 7: "BCT", | ||
| 8: "ORC", | ||
| 9: "ORCC", -9: "ORCC", | ||
| 10: "ORCF", | ||
| 11: "ORCI", | ||
| 12: "MCL", -12: "MCL", | ||
| 13: "MCLC", | ||
| 14: "TRI", | ||
| } | ||
|
|
||
|
|
||
| def _get_cell_from_ibrav(system: dict) -> List[List[float]]: | ||
| ibrav = int(system.get("ibrav", 0)) | ||
| lattice_type = IBRAV_TO_LATTICE_TYPE.get(ibrav) | ||
| if lattice_type is None: | ||
| raise ValueError(f"Unsupported ibrav={ibrav}") | ||
|
|
||
| has_celldm = "celldm1" in system | ||
|
|
||
| if has_celldm: | ||
| a = float(system["celldm1"]) * COEFFICIENTS["BOHR_TO_ANGSTROM"] | ||
| b = a * float(system.get("celldm2", 1)) | ||
| c = a * float(system.get("celldm3", 1)) | ||
| # celldm(4,5,6) are cosines → convert to degrees | ||
| alpha = math.degrees(math.acos(float(system.get("celldm4", 0)))) | ||
| beta = math.degrees(math.acos(float(system.get("celldm5", 0)))) | ||
| gamma = math.degrees(math.acos(float(system.get("celldm6", 0)))) | ||
| else: | ||
| a = float(system.get("a", 1)) | ||
| b = float(system.get("b", a)) | ||
| c = float(system.get("c", a)) | ||
| alpha = math.degrees(math.acos(float(system["cosbc"]))) if "cosbc" in system else float(system.get("alpha", 90)) | ||
| beta = math.degrees(math.acos(float(system["cosac"]))) if "cosac" in system else float(system.get("beta", 90)) | ||
| gamma = math.degrees(math.acos(float(system["cosab"]))) if "cosab" in system else float(system.get("gamma", 90)) | ||
|
|
||
| lattice_config = LatticeSchema(type=lattice_type, a=a, b=b, c=c, alpha=alpha, beta=beta, gamma=gamma) | ||
|
|
||
| return get_primitive_lattice_vectors_from_config(lattice_config) | ||
|
|
||
|
|
||
| class PwInputFile: | ||
| def __init__(self, input_text: str): | ||
| text = remove_comments_from_source_code( | ||
| remove_comments_from_source_code(input_text, language="fortran"), language="python" | ||
| ) | ||
| parser = EspressoPwxStdinParser(text) | ||
|
|
||
| system = parser.get_namelist("SYSTEM") | ||
| ibrav = int(system.get("ibrav", 0)) | ||
|
|
||
| celldm1_angstrom = float(system["celldm1"]) * COEFFICIENTS["BOHR_TO_ANGSTROM"] if "celldm1" in system else None | ||
|
|
||
| # Delegate crystal lattice calculation based on ibrav value | ||
| cell = parser.get_card_cell_parameters(celldm1_angstrom) if ibrav == 0 else _get_cell_from_ibrav(system) | ||
|
|
||
| atom_names, positions = parser.get_card_atomic_positions(cell, celldm1_angstrom) | ||
|
|
||
| self.structure = { | ||
| "cell": cell, | ||
| "atom_names": atom_names, | ||
| "positions": positions, | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Git LFS file not shown
Git LFS file not shown
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 think we should consider the rounding precision for this. Such as RoundNumericValuesMixin in https://github.com/Exabyte-io/made/blob/bfa20b8e723baa55a3b1738e0c4dd100ebec8f50/src/py/mat3ra/made/lattice.py#L12
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.
See if https://github.com/Exabyte-io/parsers/pull/1/changes is useful