Ghostly is a package to perform modification of ghost (dummy) atom bonded terms for alchemical free energy calculations, using the approach described in the paper "Dummy Atoms in Alchemical Free Energy Calculations", available here. These modifications were designed to solve two key issues:
-
To ensure that ghost atoms only give a multiplicative contribution to the partition function, which will cancel when computing double free-energy differences.
-
To avoid spurious coupling between the physical and ghost systems, which can affect the equilibrium geometry of the physical system.
Ghostly implements many extensions beyond the original modification scheme to handle the diversity of perturbations encountered in practice:
- Anchor selection scoring: physical anchor atoms are scored to avoid transmuting or bridge atoms, preventing geometrically inconsistent constraints.
- Ring bridge handling: ring bridges are not stiffened. Instead, their improper dihedrals with a single ghost are kept, holding the ghost in the plane of the ring, where the rigid ring keeps the coupling acceptable. All other bridges are stiffened.
- Junction planarity: whether a triple junction, or a bridge for rotamer detection, is planar is decided from the energy needed to flatten the angle terms between its neighbours.
- Residual term cleanup: a post-processing pass removes mixed improper dihedrals (other than those at ring bridges) and cross-bridge dihedrals missed by the per-bridge junction handlers, as well as angles where a ghost atom is the central atom and both terminal atoms are physical.
- Mixed dihedral softening: surviving mixed ghost/physical dihedrals can
be softened via
--soften-anchorsto allow ghost groups to reorient and avoid steric clashes at small λ. - Rotamer stiffening:
--stiffen-rotamersreplaces anchor dihedrals across rotatable bonds, i.e. those not in a ring whose bridge atom is neither planar nor linear, with a stiff single-well cosine to control ghost orientation through flexible bonds. - Ring-breaking perturbations: adjacent bridges with independent ghost groups retain each other as physical neighbours; angles with a ghost central atom spanning two physical neighbours are replaced by a linear spacer (180°, soft force constant); and angles spanning the ring-making/breaking bond are removed in the state where that bond is absent.
Ghostly is incorporated into the SOMD2 free-energy perturbation engine.
See the examples directory for more details.
Install ghostly directly from the openbiosim channel:
conda install -c conda-forge -c openbiosim ghostly
Or, for the development version:
conda install -c conda-forge -c openbiosim/label/dev ghostly
To install from source using pixi, which will automatically create an environment with all required dependencies (including pre-built Sire and BioSimSpace):
git clone https://github.com/openbiosim/ghostly
cd ghostly
pixi install
pixi shell
pip install -e .
If you are developing across the full OpenBioSim stack, first install Sire from source by following the instructions here, then activate its pixi environment:
pixi shell --manifest-path /path/to/sire/pixi.toml -e dev
You may also need to install other packages from source, e.g. BioSimSpace:
pip install -e /path/to/biosimspace
Then install ghostly into the environment:
pip install -e .
You should now have a ghostly executable in your path. To test, run:
ghostly --help
Pre-commit hooks are used to ensure consistent code formatting and linting. To set up pre-commit in your development environment:
pixi shell -e dev
pre-commit install
This will run ruff formatting and linting checks automatically on each commit. To run the checks manually against all files:
pre-commit run --all-files
Ghostly requires topology and coordinate files for the reference and perturbed molecules
as input, along with an optional mapping dictionary that specifies the mapping between
atoms in the end states. The molecular inputs can be in any valid file format supported
by Sire. The mapping should be a string representation
of a dictionary, where the keys are atom indices in the reference state and the values
are the corresponding atom indices in the perturbed state. This allows the mapping to
be generated programmatically by any suitable external tool.
ghostly --reference reference.* --perturbed.* --mapping '{0: 0, 1: 4, 2: 3, 3: 2, 4: 1}' --log-level debugAlternatively, you can pass a stream file containing a perturbable BioSimSpace
system, which already contains the merged end states, using the --system option.
ghostly --system system.bss --log-level debugNote
The --system option takes precedence over the --reference and --perturbed options.
When finished, the program will output a BioSimSpace
stream file for the perturbable molecule, or AMBER or GROMACS files for the two end states.
The format can be specified using the the --output-format option. If you require input
for a free-energy perturbation simulation, e.g. a hybrid GROMACS topology file, then you can
use the stream file with BioSimSpace to generate the
required input files. Additionally, the program will output a JSON file summarising the
modifications that were made.
Note
When a stream file is used as input, the --mapping option is ignored. and
the output will always be a stream file, regardless of the --output-format option.
Modified molecules in the stream file record the options used in a
ghostly_options property, and ghostly will refuse to modify them again. To
apply new modifications on top of the existing ones, use the --force option.
Please run ghostly --help for more details of other configuration options.