from scm.plams import packmol, Molecule
from .APPLEandP_atomtyper import get_APPLEandP_atomtypes
from typing import List
[docs]def appleandp_packmol(molecules: List[Molecule], forcefield_file: str, **kwargs):
"""
molecules: list of Molecule
If they are ions they should have the molecule.properties.charge set to the charge
forcefield_file: str
The force field file will be written here. It will be overwritten if it already exists
``**kwargs``: various options
See the documentation for the ``packmol()`` function
Returns: a PLAMS Molecule created with packmol
This function differs from the PLAMS implementation of packmol in that it also writes out a force field file for use with APPLE&P.
"""
# Build a box with packmol:
box = packmol(molecules=molecules, **kwargs)
# Define all the species we have in the box:
label2charge = {mol.label(): mol.properties.get("charge", 0) for mol in molecules}
# Assign bonds and atom-types for the box and the .ff file for that system:
box, forcefield = get_APPLEandP_atomtypes(box, label2charge=label2charge)
with open(forcefield_file, "w") as f:
f.write(forcefield)
return box