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

_mtp.py from_config() feature update #618

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
16 changes: 15 additions & 1 deletion maml/apps/pes/_mtp.py
Original file line number Diff line number Diff line change
Expand Up @@ -779,14 +779,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
Expand All @@ -799,8 +801,20 @@ 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])]
dsun980701 marked this conversation as resolved.
Show resolved Hide resolved
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 'default_element_ordering' argument to keep original order.", ImportWarning)
dsun980701 marked this conversation as resolved.
Show resolved Hide resolved
elements = ordered_elements
dsun980701 marked this conversation as resolved.
Show resolved Hide resolved
mtp.elements = elements

return mtp
Loading
Loading