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

BUG:ForceFieldRelaxMaker does not compatible with molecule #1123

Open
yaoyi92 opened this issue Feb 14, 2025 · 4 comments
Open

BUG:ForceFieldRelaxMaker does not compatible with molecule #1123

yaoyi92 opened this issue Feb 14, 2025 · 4 comments

Comments

@yaoyi92
Copy link

yaoyi92 commented Feb 14, 2025

Describe the bug
ForceFieldRelaxMaker does not compatible with molecule. Is there any effort in making them compatible with each other?

To Reproduce
The code to generate the problem:

from atomate2.forcefields.jobs import ForceFieldRelaxMaker
from pymatgen.core import Molecule
from jobflow import run_locally
from atomate2.forcefields import MLFF

molecule = Molecule.from_str(
"""3
Properties=species:S:1:pos:R:3 pbc="F F F"
O 0.0 0.0 0.0
H 1.0 0.0 0.0
H 0.0 1.0 0.0
""",
fmt="xyz",
)
job_relax = ForceFieldRelaxMaker(
    force_field_name = MLFF.MACE,
    relax_kwargs = {'fmax':0.025}).make(molecule)
response_relax = run_locally(job_relax)

And here is the result.

2025-02-14 15:13:45,456 INFO Started executing jobs locally
2025-02-14 15:13:45,463 INFO Starting job - Force field relax (bb32706c-9a5c-4f38-986f-141ccfd08f64)
/home/yiy/Test/000-active-learning-workflow/test_env/mace_env/lib/python3.10/site-packages/e3nn/o3/_wigner.py:10: FutureWarning: You are using `torch.load` with `weights_only=False` (the current default value), which uses the default pickle module implicitly. It is possible to construct malicious pickle data which will execute arbitrary code during unpickling (See https://github.com/pytorch/pytorch/blob/main/SECURITY.md#untrusted-models for more details). In a future release, the default value for `weights_only` will be flipped to `True`. This limits the functions that could be executed during unpickling. Arbitrary objects will no longer be allowed to be loaded via this mode unless they are explicitly allowlisted by the user via `torch.serialization.add_safe_globals`. We recommend you start setting `weights_only=True` for any use case where you don't have full control of the loaded file. Please open an issue on GitHub for any issues related to this experimental feature.
  _Jd, _W3j_flat, _W3j_indices = torch.load(os.path.join(os.path.dirname(__file__), 'constants.pt'))
cuequivariance or cuequivariance_torch is not available. Cuequivariance acceleration will be disabled.
Using medium MPA-0 model as default MACE-MP model, to use previous (before 3.10) default model please specify 'medium' as model argument
Using Materials Project MACE for MACECalculator with /home/yiy/.cache/mace/macempa0mediummodel
Using float32 for MACECalculator, which is faster but less accurate. Recommended for MD. Use float64 for geometry optimization.
['/home/yiy/.cache/mace/macempa0mediummodel']
/home/yiy/Test/000-active-learning-workflow/test_env/mace_env/lib/python3.10/site-packages/mace/calculators/mace.py:140: FutureWarning: You are using `torch.load` with `weights_only=False` (the current default value), which uses the default pickle module implicitly. It is possible to construct malicious pickle data which will execute arbitrary code during unpickling (See https://github.com/pytorch/pytorch/blob/main/SECURITY.md#untrusted-models for more details). In a future release, the default value for `weights_only` will be flipped to `True`. This limits the functions that could be executed during unpickling. Arbitrary objects will no longer be allowed to be loaded via this mode unless they are explicitly allowlisted by the user via `torch.serialization.add_safe_globals`. We recommend you start setting `weights_only=True` for any use case where you don't have full control of the loaded file. Please open an issue on GitHub for any issues related to this experimental feature.
  torch.load(f=model_path, map_location=device)
Default dtype float32 does not match model dtype float64, converting models to float32.
/home/yiy/Test/000-active-learning-workflow/test_env/mace_env/lib/python3.10/site-packages/atomate2/ase/utils.py:368: FutureWarning: Please use atoms.calc = calc
  atoms.set_calculator(self.calculator)
2025-02-14 15:13:55,169 INFO Force field relax failed with exception:
Traceback (most recent call last):
  File "/home/yiy/Test/000-active-learning-workflow/test_env/mace_env/lib/python3.10/site-packages/jobflow/managers/local.py", line 117, in _run_job
    response = job.run(store=store)
  File "/home/yiy/Test/000-active-learning-workflow/test_env/mace_env/lib/python3.10/site-packages/jobflow/core/job.py", line 604, in run
    response = function(*self.function_args, **self.function_kwargs)
  File "/home/yiy/Test/000-active-learning-workflow/test_env/mace_env/lib/python3.10/site-packages/atomate2/forcefields/jobs.py", line 169, in make
    return ForceFieldTaskDocument.from_ase_compatible_result(
  File "/home/yiy/Test/000-active-learning-workflow/test_env/mace_env/lib/python3.10/site-packages/atomate2/forcefields/schemas.py", line 153, in from_ase_compatible_result
    return cls.from_ase_task_doc(ase_task_doc, **ff_kwargs)
  File "/home/yiy/Test/000-active-learning-workflow/test_env/mace_env/lib/python3.10/site-packages/atomate2/ase/schemas.py", line 253, in from_ase_task_doc
    return cls(**task_document_kwargs)
  File "/home/yiy/Test/000-active-learning-workflow/test_env/mace_env/lib/python3.10/site-packages/pydantic/main.py", line 214, in __init__
    validated_self = self.__pydantic_validator__.validate_python(data, self_instance=self)
pydantic_core._pydantic_core.ValidationError: 1 validation error for ForceFieldTaskDocument
structure
  Value error, Must provide Structure, the as_dict form, or the proper [type=value_error, input_value=Molecule Summary
Site: O ...-0.0655, 1.0145, 0.0000), input_type=Molecule]
    For further information visit https://errors.pydantic.dev/2.10/v/value_error

INFO:jobflow.managers.local:Force field relax failed with exception:
Traceback (most recent call last):
  File "/home/yiy/Test/000-active-learning-workflow/test_env/mace_env/lib/python3.10/site-packages/jobflow/managers/local.py", line 117, in _run_job
    response = job.run(store=store)
  File "/home/yiy/Test/000-active-learning-workflow/test_env/mace_env/lib/python3.10/site-packages/jobflow/core/job.py", line 604, in run
    response = function(*self.function_args, **self.function_kwargs)
  File "/home/yiy/Test/000-active-learning-workflow/test_env/mace_env/lib/python3.10/site-packages/atomate2/forcefields/jobs.py", line 169, in make
    return ForceFieldTaskDocument.from_ase_compatible_result(
  File "/home/yiy/Test/000-active-learning-workflow/test_env/mace_env/lib/python3.10/site-packages/atomate2/forcefields/schemas.py", line 153, in from_ase_compatible_result
    return cls.from_ase_task_doc(ase_task_doc, **ff_kwargs)
  File "/home/yiy/Test/000-active-learning-workflow/test_env/mace_env/lib/python3.10/site-packages/atomate2/ase/schemas.py", line 253, in from_ase_task_doc
    return cls(**task_document_kwargs)
  File "/home/yiy/Test/000-active-learning-workflow/test_env/mace_env/lib/python3.10/site-packages/pydantic/main.py", line 214, in __init__
    validated_self = self.__pydantic_validator__.validate_python(data, self_instance=self)
pydantic_core._pydantic_core.ValidationError: 1 validation error for ForceFieldTaskDocument
structure
  Value error, Must provide Structure, the as_dict form, or the proper [type=value_error, input_value=Molecule Summary
Site: O ...-0.0655, 1.0145, 0.0000), input_type=Molecule]
    For further information visit https://errors.pydantic.dev/2.10/v/value_error

2025-02-14 15:13:55,170 INFO Finished executing jobs locally
INFO:jobflow.managers.local:Finished executing jobs locally

Expected behavior
No validation error.

@JaGeo
Copy link
Member

JaGeo commented Feb 14, 2025

Thank you for contacting us.

I think the answer has several layers:

  • the code atomate2 originally started with VASP and other codes ideal for crystals and therefore Structure offers itself as a good representation
  • forcefields were initially implemented as a replacement for VASP jobs and we nearly one have workflows for crystalline properties
  • you can likely already use the workflows for molecules when you insert a molecule in a vacuum

Overall, i would not call this a bug.

Nevertheless, i believe, one can add the Molecule as an alternative to Structure. Is there a specific usecase you have in mind? Do you want to use it in larger workflows as well? PRs are welcome.

@yaoyi92
Copy link
Author

yaoyi92 commented Feb 14, 2025

Thank you for your fast response and helpful information. I can try to add the feature if no one has already work on it.

@JaGeo
Copy link
Member

JaGeo commented Feb 14, 2025

Yes, sure, @yaoyi92 !

You might also want to check out https://github.com/Quantum-Accelerators/quacc which has a few more workflows and codes for molcules already.

@yaoyi92
Copy link
Author

yaoyi92 commented Feb 14, 2025

Thank you for the helpful information!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants