Skip to content

Data

Locators for the data files bundled with MolPy — built-in force fields (oplsaa.xml, clp.xml, tip3p.xml, alpha.ff, …) and other packaged assets. These helpers return filesystem paths you can hand to a reader; they do not parse anything themselves. Available via import molpy as mp (mp.data.get_forcefield_path).

Quick reference

Symbol Summary Preferred for
get_forcefield_path(name) Path to a bundled force-field file Loading a built-in force field
list_forcefields() Names of the bundled force fields Discovering what ships with MolPy
get_path(name) Path to any bundled data file Accessing a packaged asset
list_files() Names of all bundled data files Enumerating packaged assets
exists(name) Whether a bundled file is present Guarding optional assets
import molpy as mp

ff = mp.io.read_xml_forcefield(mp.data.get_forcefield_path("oplsaa.xml"))

Full API

data

MolPy Data Module - Access to built-in data files.

This module provides a unified interface for accessing built-in data files such as force field parameters, molecule templates, and other resources.

Usage

from molpy.data import get_path, list_files from molpy.data.forcefield import get_forcefield_path

Get path to a data file

path = get_path("forcefield/oplsaa.xml")

List available files in a subdirectory

files = list_files("forcefield")

Get force field path (convenience function)

ff_path = get_forcefield_path("oplsaa.xml")

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.data import exists
>>> if exists("forcefield/oplsaa.xml"):
...     print("File exists")

get_forcefield_path

get_forcefield_path(filename)

Get the path to a force field file.

Parameters:

Name Type Description Default
filename str

Name of the force field file (e.g., "oplsaa.xml")

required

Returns:

Type Description
Path

Path object pointing to the force field file

Raises:

Type Description
FileNotFoundError

If the file does not exist

Examples:

>>> from molpy.data import get_forcefield_path
>>> path = get_forcefield_path("oplsaa.xml")
>>> print(path)
/path/to/molpy/data/forcefield/oplsaa.xml

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/oplsaa.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.data import get_path
>>> path = get_path("forcefield/oplsaa.xml")
>>> print(path)
/path/to/molpy/data/forcefield/oplsaa.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.data import list_files
>>> for file in list_files("forcefield"):
...     print(file)
forcefield/oplsaa.xml
forcefield/tip3p.xml

list_forcefields

list_forcefields()

List all available force field files.

Returns:

Type Description
list[str]

List of force field filenames

Examples:

>>> from molpy.data import list_forcefields
>>> forcefields = list_forcefields()
>>> print(forcefields)
['oplsaa.xml', 'tip3p.xml']