Path D - Module 28: The MolSysBuilder API#
In some biophysical studies, you need to add specific solvent structures. In this module, you will learn to build a “Hydrated Potassium Ion” (an ion surrounded by 8 water molecules in a specific geometry) from scratch.
While editing, msm.get(builder, ...) can inspect the complete chemical/topological and structural state stored by the builder. Molecular-mechanics data and per-structure chemical-state associations are added to the materialized MolSys, not stored in the builder.
Conversions among MolSys, MolSysBuilder, and MolSysDict report fidelity exhaustively. In selected exports, atom order is canonical and structure_indices retains the requested order; strict=True rejects detected reduced-schema loss.
import numpy as np
import molsysmt as msm
from molsysmt import pyunitwizard as puw
builder = msm.MolSysBuilder()
potassium = builder.add_atom(atom_name='K', atom_type='K')
group = builder.add_group([potassium], group_name='K', group_type='ion')
molecule = builder.add_molecule([group], molecule_name='Solvated Ion', molecule_type='ion')
builder.add_entity([molecule], entity_name='Solvated Ion', entity_type='ion')
builder.set_coordinates(puw.quantity(np.array([[0.0, 0.0, 0.0]]), 'nm'))
hydrated_ion_scaffold = builder.build()
print("Hydrated ion scaffold built.")