-
Notifications
You must be signed in to change notification settings - Fork 98
_mtp.py from_config() feature update #618
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
dsun980701
wants to merge
12
commits into
materialyzeai:master
Choose a base branch
from
dsun980701:master
base: master
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 9 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
867abcd
Update _mtp.py
dsun980701 d3878a1
Update _mtp.py
dsun980701 231754d
Add files via upload
dsun980701 28dad5c
Update test_mtp.py
dsun980701 985c0d4
pre-commit auto-fixes
pre-commit-ci[bot] a76fea9
Update _mtp.py
dsun980701 4af201c
pre-commit auto-fixes
pre-commit-ci[bot] eac43cb
Update _mtp.py
dsun980701 637dc78
pre-commit auto-fixes
pre-commit-ci[bot] f4076b6
Update _mtp.py
dsun980701 5a68e0a
Update _signal_processing.py
dsun980701 d8994c5
pre-commit auto-fixes
pre-commit-ci[bot] 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
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -10,14 +10,15 @@ | |||||||
| import re | ||||||||
| import shutil | ||||||||
| import subprocess | ||||||||
| import warnings | ||||||||
| from collections import OrderedDict | ||||||||
| from shutil import which | ||||||||
|
|
||||||||
| import numpy as np | ||||||||
| from monty.io import zopen | ||||||||
| from monty.serialization import loadfn | ||||||||
| from monty.tempfile import ScratchDir | ||||||||
| from pymatgen.core import Lattice, Structure | ||||||||
| from pymatgen.core import Element, Lattice, Structure | ||||||||
|
|
||||||||
| from maml.utils import check_structures_forces_stresses, convert_docs, pool_from | ||||||||
|
|
||||||||
|
|
@@ -779,14 +780,16 @@ def evaluate(self, test_structures, test_energies, test_forces, test_stresses=No | |||||||
| return df_orig, df_predict | ||||||||
|
|
||||||||
| @staticmethod | ||||||||
| def from_config(filename, elements): | ||||||||
| def from_config(filename, elements, default_element_ordering=True): | ||||||||
| """ | ||||||||
| Initialize potentials with parameters file. | ||||||||
|
|
||||||||
| Args: | ||||||||
| filename (str): The file storing parameters of potentials, filename should | ||||||||
| ends with ".mtp". | ||||||||
| elements (list): The list of elements. | ||||||||
| default_element_ordering (bool): If True, elements argument is ordered following the | ||||||||
| convention of Pauling electronegativity. If False, given order is kept. | ||||||||
|
|
||||||||
| Returns: | ||||||||
| MTPotential | ||||||||
|
|
@@ -799,8 +802,25 @@ def from_config(filename, elements): | |||||||
| key = line.rstrip().split(" = ")[0] | ||||||||
| value = json.loads(line.rstrip().split(" = ")[1].replace("{", "[").replace("}", "]")) | ||||||||
| param[key] = value | ||||||||
| num_species = -1 | ||||||||
| for line in lines: | ||||||||
| if "species_count" in line: | ||||||||
| num_species = int(line.split()[2]) | ||||||||
| break | ||||||||
| if len(set(elements)) != num_species: | ||||||||
| raise ValueError("Inconsistent number of species between the provided .mtp file and the elements argument") | ||||||||
|
|
||||||||
| mtp = MTPotential(param=param) | ||||||||
| if default_element_ordering: | ||||||||
| ordered_elements = [str(x) for x in sorted([Element(x) for x in elements])] | ||||||||
| if elements != ordered_elements: | ||||||||
| warnings.warn( | ||||||||
| f"Order for the elements has been altered from {elements} to {ordered_elements} to ensure" | ||||||||
| + " consistency with default element ordering in maml during MTP fitting. Change the" | ||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider using implicit string concatenation for better readability. - f"Order for the elements has been altered from {elements} to {ordered_elements} to ensure"
- + " consistency with default element ordering in maml during MTP fitting. Change the"
+ f"Order for the elements has been altered from {elements} to {ordered_elements} to ensure consistency with default element ordering in maml during MTP fitting. Change the"Committable suggestion
Suggested change
|
||||||||
| + " 'default_element_ordering' argument to keep original order.", | ||||||||
| ImportWarning, | ||||||||
| ) | ||||||||
| elements = ordered_elements | ||||||||
|
dsun980701 marked this conversation as resolved.
|
||||||||
| mtp.elements = elements | ||||||||
|
|
||||||||
| return mtp | ||||||||
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.
Uh oh!
There was an error while loading. Please reload this page.