Skip to content

Resources

Locators for the data files bundled with MolPy — built-in force fields (tip3p.xml, an OpenMM XML; clp.xml, the CL&P typing force field read by mp.ff.typifier.OplsAaTypifier(path)) and other packaged assets. The CL&Pol Drude table ships with molrs (mp.ff.params.clpol_polarizability()). These helpers return filesystem paths you can hand to a reader; they do not parse anything themselves. Available via import molpy as mp (mp.resources.get_path("forcefield/tip3p.xml")).

OPLS-AA is not a bundled file: it ships with molrs and comes from mp.ff.typifier.OplsAaTypifier() — .source_forcefield() returns every OPLS-AA type, .forcefield() only the types assigned by the last .typify(...).

Quick reference

Symbol Summary Preferred for
get_path(name) Path to a bundled data file ("forcefield/tip3p.xml") Loading a built-in force field or any packaged asset
list_files(subdir) Names of the bundled data files (list_files("forcefield")) Discovering what ships with MolPy
exists(name) Whether a bundled file is present Guarding optional assets
import molpy as mp

ff = mp.io.read_openmm_xml_forcefield(mp.resources.get_path("forcefield/tip3p.xml"))

opls = mp.ff.typifier.OplsAaTypifier().source_forcefield() # all OPLS-AA types, from molrs

Full API

resources

molpy's bundled resource files: force-field XMLs and other data shipped with the package.

Usage::

from molpy.resources import get_path, list_files

path = get_path("forcefield/tip3p.xml")   # absolute path to a bundled file
files = list(list_files("forcefield"))     # every file in a subdirectory

exists

exists(relative_path)

Check if a data file exists.

Parameters:

Name Type Description Default
relative_path str | Path

Relative path to the data file

required

Returns:

Type Description
bool

True if the file exists, False otherwise

Examples:

>>> from molpy.resources import exists
>>> if exists("forcefield/tip3p.xml"):
...     print("File exists")

get_path

get_path(relative_path)

Get the absolute path to a data file.

Parameters:

Name Type Description Default
relative_path str | Path

Relative path to the data file (e.g., "forcefield/tip3p.xml")

required

Returns:

Type Description
Path

Path object pointing to the data file

Raises:

Type Description
FileNotFoundError

If the file does not exist

Examples:

>>> from molpy.resources import get_path
>>> path = get_path("forcefield/tip3p.xml")
>>> print(path)
/path/to/molpy/resources/forcefield/tip3p.xml

list_files

list_files(subdirectory='', exclude_python=True)

List all files in a data subdirectory.

Parameters:

Name Type Description Default
subdirectory str | Path

Subdirectory to list (e.g., "forcefield"), empty string for root

''
exclude_python bool

If True, exclude Python files (init.py, *.py, etc.)

True

Yields:

Type Description
str

Relative paths to files in the subdirectory

Examples:

>>> from molpy.resources import list_files
>>> for file in list_files("forcefield"):
...     print(file)
forcefield/tip3p.xml
forcefield/tip3p.xml