Skip to content

API Reference

A class that holds the topology and coordinate template of a molecule.

from_smiles(smiles: str, name: str = None) -> Molecule

Section titled “from_smiles(smiles: str, name: str = None) -> Molecule”

Generates a molecule from a SMILES string.

ArgumentTypeDefaultDescription
smilesstr(Required)SMILES string. Connection points can be marked with *.
namestr"MOL"Name of the molecule.

from_rdkit(mol: rdkit.Chem.Mol, name: str = None) -> Molecule

Section titled “from_rdkit(mol: rdkit.Chem.Mol, name: str = None) -> Molecule”

Generates a Molecule from an RDKit Mol object. Coordinates and connectivity are preserved.

from_openff(obj: Union[Molecule, Topology, Interchange]) -> Molecule

Section titled “from_openff(obj: Union[Molecule, Topology, Interchange]) -> Molecule”

Imports a Molecule from an OpenFF Molecule, Topology, or Interchange object. Partial charges (e.g., AM1-BCC) and connectivity are preserved.

from_polymer(monomer: Molecule, degree: int, head: int = None, tail: int = None, h_leaving: int = None, t_leaving: int = None, tacticity: str = None, name: str = None) -> Molecule

Section titled “from_polymer(monomer: Molecule, degree: int, head: int = None, tail: int = None, h_leaving: int = None, t_leaving: int = None, tacticity: str = None, name: str = None) -> Molecule”

Generates a polymer chain Molecule from a monomer Molecule.

ArgumentTypeDefaultDescription
monomerMolecule(Required)The repeating unit as an fbtk.Molecule.
degreeint(Required)Degree of polymerization.
headintNoneHeavy atom index for the head connection. Auto-resolved from * if omitted.
tailintNoneHeavy atom index for the tail connection. Auto-resolved from * if omitted.
h_leavingintNoneIndex of the leaving atom at the head side.
t_leavingintNoneIndex of the leaving atom at the tail side.
tacticitystrNoneOne of "isotactic", "syndiotactic", or "atactic".
namestrNoneName of the generated chain.

from_file(path: str, name: str = None, format: str = None) -> Molecule

Section titled “from_file(path: str, name: str = None, format: str = None) -> Molecule”

Generates a Molecule from a file. Supports .mol and .mol2 natively.

ArgumentTypeDefaultDescription
pathstr(Required)Path to the file.
namestr"MOL"Name of the molecule.
formatstrNone"mol" or "mol2". Auto-detected from extension if omitted.

Returns atom coordinates as an (N, 3) NumPy array.

get_bonds() -> List[Tuple[int, int, float]]

Section titled “get_bonds() -> List[Tuple[int, int, float]]”

Returns a list of all bonds in the molecule as (atom_i, atom_j, bond_order).

Returns a list of partial charges for all atoms in the molecule.

Returns a list of chemical symbols for all atoms in the molecule.

Calculates and assigns Gasteiger partial charges.

relax(steps: int = 1000, threshold: float = 1.0, verbose: bool = True, num_threads: int = 0, cutoff: float = 6.0, history_size: int = 10)

Section titled “relax(steps: int = 1000, threshold: float = 1.0, verbose: bool = True, num_threads: int = 0, cutoff: float = 6.0, history_size: int = 10)”

Performs structural optimization on the single molecule template.

ArgumentTypeDefaultDescription
stepsint1000Maximum optimization steps.
thresholdfloat1.0Convergence threshold ($F_{max}$, kcal/mol/Å).
verboseboolTrueShow optimization logs.
num_threadsint0Threads for parallel computation (0 for auto).
cutofffloat6.0Cutoff radius for non-bonded interactions (Å).
history_sizeint10History size for L-BFGS convergence.

Saves the Molecule template to a file (default .mol2).

Converts to an RDKit Mol object.

to_openff(forcefield: str = None) -> Union[openff.toolkit.Molecule, openff.interchange.Interchange]

Section titled “to_openff(forcefield: str = None) -> Union[openff.toolkit.Molecule, openff.interchange.Interchange]”

Converts to an OpenFF object. Returns a Molecule if forcefield is None, or an Interchange if provided.


The central class for constructing unit cells and bulk systems.

Builder(box_size: List[float] = None, density: float = None)

Section titled “Builder(box_size: List[float] = None, density: float = None)”

Initializes the Builder. Progress is reported every 2000 atoms during construction.

add_molecule(molecule: Molecule, count: int)

Section titled “add_molecule(molecule: Molecule, count: int)”

Adds a specified count of an fbtk.Molecule template.

add_molecule_smiles(name: str, count: int, smiles: str)

Section titled “add_molecule_smiles(name: str, count: int, smiles: str)”

Adds small molecules directly from SMILES.

add_polymer(name: str, count: int, degree: int, smiles: str, ...)

Section titled “add_polymer(name: str, count: int, degree: int, smiles: str, ...)”

Generates and adds polymer chains.

Loads a configuration from a YAML recipe file.

Executes the packing algorithm and returns a System object.

Performs structural relaxation on the constructed bulk system. Arguments are the same as Molecule.relax().


A class for operating on constructed or loaded bulk systems.

from_file(path: str, format: str = None) -> System

Section titled “from_file(path: str, format: str = None) -> System”

Loads a system from a file (currently .mol2 only).

from_openff(obj: Union[Molecule, Topology, Interchange]) -> System

Section titled “from_openff(obj: Union[Molecule, Topology, Interchange]) -> System”

Imports a System from an OpenFF object. Box vectors and partial charges are automatically synchronized and converted to FBTK units (Å).

Returns coordinates of all atoms as an (N, 3) NumPy array.

Returns a list of partial charges for all atoms in the system.

Returns a list of chemical symbols for all atoms in the system.

Calculates Gasteiger partial charges for the entire system.

relax(steps: int = 1000, threshold: float = 1.0, verbose: bool = True, num_threads: int = 0, cutoff: float = 6.0, history_size: int = 10)

Section titled “relax(steps: int = 1000, threshold: float = 1.0, verbose: bool = True, num_threads: int = 0, cutoff: float = 6.0, history_size: int = 10)”

Performs structural relaxation using the UFF-MD (FIRE) algorithm.

ArgumentTypeDefaultDescription
stepsint1000Maximum optimization steps.
thresholdfloat1.0Convergence threshold. 1.0 is recommended for bulk systems.
verboseboolTrueLog energy and $F_{max}$ progress.
num_threadsint0Threads for computation (0 for auto).
cutofffloat6.0Cutoff radius for non-bonded (Van der Waals) interactions (Å).
history_sizeint10History size for convergence tracking.

Converts to an ASE Atoms object.

Converts to an RDKit Mol object.

to_openff(forcefield: str = None) -> Union[openff.toolkit.Topology, openff.interchange.Interchange]

Section titled “to_openff(forcefield: str = None) -> Union[openff.toolkit.Topology, openff.interchange.Interchange]”

Converts to an OpenFF object. Box vectors are automatically converted to nm and synchronized.

Saves the bulk system to a file (default .mol2).


Creates an FBTK System from an ASE Atoms object.

compute_rdf(...) -> Tuple[np.ndarray, np.ndarray]

Section titled “compute_rdf(...) -> Tuple[np.ndarray, np.ndarray]”

Computes the Radial Distribution Function (RDF).

compute_msd(...) -> Tuple[np.ndarray, np.ndarray]

Section titled “compute_msd(...) -> Tuple[np.ndarray, np.ndarray]”

Computes the Mean Squared Displacement (MSD).


Selectors used in analysis functions.

SyntaxDescription
element {Sym}Select specific element (e.g., element C).
resname {Name}Select specific residue name.
index {Start} to {End}Select atom ID range (inclusive, 0-indexed).
A and BIntersection of conditions.
A with B / A - BPair separation for RDF.
not {Query}Negation of condition.

FBTK features a high-speed native SMILES parser based on the purr crate, allowing 3D structure generation without RDKit.

  • Capabilities:
    • Aliphatic/aromatic, branched, and cyclic structures.
    • Formal charges (e.g., [NH4+], [O-]).
    • Explicit hydrogen counts within brackets.
  • Limitations:
    • Strict stereochemistry (Cis/Trans, R/S) resolution is currently in development.
  • Recommendation: For complex stereochemical requirements, use Molecule.from_rdkit(mol).

FBTK utilizes Rayon as a global thread pool.

  • Applied to: relax, compute_rdf, compute_msd, get_all_distances, get_neighbor_list.