Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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])]
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)
elements = ordered_elements
mtp.elements = elements

return mtp
Loading