Free Energy

Creating a Alchemical Free Energy Simulator Project

Let’s walk through how to create a Alchemical Free Energy project.

An AFES project needs a reference system (the receptor the ligands are placed into) and a Ligand Reader & Modeler (LRM) project (the ligands themselves). There are two ways to provide the reference system:

  1. Reference an existing Builder project (reference_project_id) — the original workflow. Build a Solution/Membrane Builder project first, then point the AFES project at it.

  2. Build from a PDB Reader project (pdb_project_id + builder_type) — the quick-build path. No separate Builder project is created; the PDB Reader system is wired directly into the AFES project and the reference build is billed as part of it.

So you need to prepare either:

  • PDB Reader → Solution Builder or Membrane Builder → Ligand Reader & Modeler, or

  • PDB Reader → Ligand Reader & Modeler (quick-build)

All builders must employ the same protein force field. Be especially careful with the ligand force field(s) applied in the Ligand Reader and Modeler—you can use multiple ligand force fields if needed.

Note

The LRM project aligns its ligands against a reference structure, and by default the SDK reuses the reference ligand stored on that project. If your AFES project was built from a different structure, pick the target ligand yourself with set_reference_ligand() (see Choosing the target ligand below). Receptors with no ligand at all are also supported — common for absolute binding.

create_project() options:

  • title (str): project title

  • reference_project_id (str): Solution Builder or Membrane Builder project id. Mutually exclusive with pdb_project_id — pass exactly one.

  • ff (ForceField): project force field amberff or charmmff (default: ForceField.AMBER)

    • PROGRAM: Available ForceField
      • AMBER: AMBERFF

      • GROMACS: AMBERFF

      • OpenMM: AMBERFF, CHARMMFF

      • BLaDE: AMBERFF, CHARMMFF

  • calculate_program (Program): (default: Program.AMBER)

  • calculate_application (Application): (default: Application.RELATIVE_BINDING)

  • amber_options (dict[str, Enum]): The default selections for amberff are as follows:

    {
        "protein": Protein.FF19SB,
        "water": Water.OPC,
        "lipid": Lipid.LIPID21,
    }
    

    lipid is required by the backend whenever ff is AMBER, even for non-membrane systems.

Quick-build options (only when pdb_project_id is set):

  • pdb_project_id (str): finished (step 5) PDB Reader project id. Not available for Application.MUTATION_FE — the backend branches on the application before it reaches the quick-build path, so a mutation project must reference a finished Builder project.

  • builder_type (BuilderType): SOLUTION or MEMBRANE. With MEMBRANE the PDB Reader project’s force field must equal ff; with SOLUTION a mismatch only prints a warning.

  • box_margin (float): water box margin (Å) for the quick-built system. MEMBRANE only.

  • lipids (list[dict]): lipid composition, one dict per lipid. MEMBRANE only. area and type are filled in from the backend’s lipid library when omitted — see Membrane quick-build below.

NOTE:

Choose Program and Application according to your free energy calculation goals. The program fixes the method, and not every program supports every application:

Program (Method)

Relative Binding

Absolute Binding

Mutation F.E.

AMBER (TI)

✔

✔

✔

GROMACS (Non-eq TI)

✔

✔

✔

OpenMM (FEP)

✔

✔

BLaDE (MSλD)

✔

✔

  • Relative Binding F.E. (RBFE): compute relative free energy between ligand A–B as defined by each morph. BLaDE evaluates a whole ligand group at once instead of pairs.

  • Absolute Binding F.E. (ABFE): perform absolute comparison of protein–ligand interaction energies. Requires Boresch restraints in step 3.

  • Mutation F.E.: compute relative change in binding affinity resulting from a specific amino acid substitution.

Here is an example workflow for AMBER-TI Relative Binding:

from molcube.free_energy.enum import *

# alt: solution_project_id = sbuilder.projectId
solution_project_id = '1910f751-a91d-450b-8634-ba3c6349dca5'

# Create a Alchemical Free Energy Simulator project
afes = molcube.create_afes_project()
afes.create_project(
    title='my_afes_project',
    reference_project_id=solution_project_id,
)

The same project built straight from a PDB Reader project instead:

afes = molcube.create_afes_project()
afes.create_project(
    title='my_afes_project',
    pdb_project_id=pdbreader.projectId,
    builder_type=BuilderType.SOLUTION,
)

Projects that can be used as a Step 1 input — Builder projects and finished PDB Reader projects — are listed by:

molcube.get_available_projects('Free Energy', category='builder')

Choosing the target ligand

The target ligand is the receptor ligand that marks the binding site. The backend uses it to work out where the LRM ligands should be placed, so it must be a residue this receptor actually contains.

List the candidates with check_reference_ligands():

>>> available_ligands = afes.check_reference_ligands()
Chain Index: HETE_C, Residue Name: 53U

Then pin one with set_reference_ligand():

afes.set_reference_ligand({'chainIndex': 'HETE_C', 'residueName': '53U'})

The choice is validated against the list above and kept for the rest of the workflow. It can also be passed inline to generate_morph_set(), processing_ligand() and generate_ligand_group() as reference_ligand=.

Note

When you can skip it — if you do not set one, the SDK falls back to the reference ligand stored on the LRM project. That works only when the LRM project was aligned against the very same structure this AFES project was built from; otherwise processing_ligand() stops and reports which ligands the receptor actually has.

Ligand-free (apo) receptors — if the receptor has no ligand at all (common for absolute binding), the list comes back empty and no target ligand is sent. Nothing extra to do.

You can read a Ligand Reader & Modeler project using the read_ligand_modeler_project() method.

>>> afes.read_ligand_modeler_project(lrmbuilder.projectId)
Available ligands for openffFast:
  - 1a
  - 1b

AMBER-TI Relative Binding

  • BASE WORKFLOW (after create_project())

    1. afes.generate_morph_set()

    • Based on the imported LRM project, recommend and generate both closed and radial morph sets:

      • Closed morph: Closed minimal perturbation path based on the clustering. (Fingerprint-based)

      • Radial morph: Radial shape of perturbation path from the ligand 1 (no clustering). (Fingerprint-based)

      • Minimum Spanning Tree morph (MST): Minimum spanning tree of the perturbation path. (MCS-based)

      • LOMAP morph: LOMAP-based perturbation path generation. (MCS-based)

      • Custom morph: Manually define perturbation path in the next step.

    • options:

      • reference_ligand (dict[str]): receptor ligand that marks the binding site — pick one from check_reference_ligands(). Optional; see Choosing the target ligand. e.g.:

        {"chainIndex": "HETE_C", "residueName": "53U"}
        
      • ligand_modeler_project_id (str): Ligand Reader & Modeler Project ID. If you have already executed the read_ligand_modeler_project method, you do not need to provide this argument.

      • ligand_ff (list[LigandForceField]): Select the ligand force fields generated in the LRM project that you want to use for Free Energy Calculation.

      • selected_ligands (dict[LigandForceField, list[str]]): Specify which ligands generated in the LRM project will be used for Free Energy Calculation, grouped by ligand force field. If you use an empty dictionary ({}), all selectable ligands will be included. (default: {})

        e.g. {LigandForceField.GAFF_FAST: [“LIG1”, “LIG2”], LigandForceField.GAFF: [“LIG3”]}

      • generate_morphset_type (GenerateMorphsetType): morphset type (default: GenerateMorphsetType.CLOSED)

    1. afes.processing_ligand()

    • Processes ligand information and prepares data for free energy calculations.

    • Step 2 precomputes core indices for all ligand pairs. Pair SVGs are fetched on demand when core indices are viewed or edited. BLaDE group preprocessing uses the dedicated group-preprocess endpoint automatically.

    1. afes.generate_system()

    • Generates a molecular system for free energy calculations based on user-specified parameters and preprocessed results.

    • For relative-binding workflows, the current perturbation paths are submitted in step 3 together with only the core-index pairs referenced by those paths.

    • options:

      • margin (float): Water box margin for the system in Å. (default: 10)

      • ion_type (str): Type of ions to use. (default: "kcl")

      • ion_conc (float): Ion concentration. (default: 0.15) Ignored when ion_neutralize is True.

      • ion_neutralize (bool): Add only the counter ions needed to neutralize the system instead of ions up to ion_conc. Mirrors the web UI’s Neutralize Only checkbox. (default: False)

      • use_hmr (bool): Whether to use hydrogen mass repartitioning. (default: False)

      • temperature (float): Temperature for the system in Kelvin. (default: 310.15)

  • Optional Methods

    1. After generate_morph_set()
      • afes.delete_morph_set()
        • Removes a morph set from the generated morph sets.

        • options:

          • lig_ff (LigandForceField): ligand force field to delete among the generated morph sets

          • morph_set (dict[str]):

            {'start': INDEX or Name, 'end': INDEX or Name}, e.g.:

            {'start': 1, 'end': 2}
            
      • afes.add_morph_set():
        • Adds a morph set to the generated morph sets.

        • options:

          • lig_ff (LigandForceField): ligand force field to add among the generated morph sets

          • morph_set (dict[str]):

            {'start': INDEX or Name, 'end': INDEX or Name}, e.g.:

            {'start': 1, 'end': 2}
            
      • afes.get_similarity_score():
        • Returns the similarity score between ligands for the specified ligand force field.

        • options:

      • afes.check_ligand_2d_structure():
        • Displays the 2D structures of two ligands for visual comparison.

        • options:

          • file_name_1 (str): The file name of the ligand you want to check, e.g.: '1a.sdf'

          • file_name_2 (str): The file name of the ligand you want to check, e.g.: '1b.sdf'

    2. After processing_ligand()
      • afes.get_core_indices()
        • Returns the core atom indices for each ligand in the morph set or ligand group.

        • options:

          • lig_ff (LigandForceField): ligand force field to check the core indices for.

          • set_num (int): set number to check core indices (default: 1)

      • afes.delete_core_indices()
        • Removes core atom indices from a ligand in the morph set or ligand group.

        • options:

          • lig_ff (LigandForceField): ligand force field from which to remove core indices.

          • set_num (int): set number from which to remove core indices. (default: 1)

          • indices (list[int]): list of core indices to remove

          • ligand_name (str): Name of the ligand from which to remove core indices

      • afes.add_core_indices()
        • Adds core atom indices to a ligand in the morph set or ligand group.

        • options:

          • lig_ff (LigandForceField): ligand force field to which to add core indices.

          • set_num (int): set number to which to add core indices. (default: 1)

          • indices (list[int]): list of core indices to add

          • ligand_name (str): Name of the ligand from which to add core indices

Now, let’s return to the AMBER-TI Relative Binding example.

The following method, based on the imported LRM project, recommends and generates both closed and radial morph sets.

Note:
  • Closed morph: Closed minimal perturbation path based on the clustering. (Fingerprint-based)

  • Radial morph: Radial shape of perturbation path from the ligand 1 (no clustering). (Fingerprint-based)

  • Minimum Spanning Tree morph (MST): Minimum spanning tree of the perturbation path. (MCS-based)

  • LOMAP morph: LOMAP-based perturbation path generation. (MCS-based)

  • Custom morph: Manually define perturbation path in the next step.

>>> selected_ligands = {
...     # or ['1a', '1b', '1c']
...     LigandForceField.OPENFF_FAST: ['1a.sdf', '1b.sdf'],
... }

>>> afes.generate_morph_set(
...     ligand_ff=[LigandForceField.OPENFF_FAST],
...     selected_ligands=selected_ligands,
...     generate_morphset_type=GenerateMorphsetType.CLOSED,
... )

Force Field: openff-fast
 Morph 1: 1a(1) -> 1b(2)

Morph set generated with threshold 1 for 1 force fields.
To update the morph set, use 'delete_morph_set()' or 'add_morph_set()' method.

The following method processes ligand information and prepares data for free energy calculations.

>>> afes.processing_ligand()
1a.sdf (51)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51

1b.sdf (51)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51

This produces an image highlighting the maximum common subgraph (MCS). If no alterations are made, these atoms will be used as the basis for alignment. If you want to add or remove atoms from the alignment group, you can use the add_core_indices() and delete_core_indices() methods.

>>> afes.delete_core_indices(
...     lig_ff=LigandForceField.OPENFF_FAST,
...     set_num=1,
...     ligand_name='1a', indices=[14])
First name: 1a, End name: 1b
1a.sdf (50)
1 2 3 4 5 6 7 8 9 10 11 12 13 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51

1b.sdf (50)
1 2 3 4 5 6 7 8 9 10 11 12 13 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51

>>> afes.add_core_indices(
...     lig_ff=LigandForceField.OPENFF_FAST,
...     set_num=1,
...     ligand_name='1a', indices=[52])
Core index 52 does not exist in the original indices.
1a.sdf (50)
1 2 3 4 5 6 7 8 9 10 11 12 13 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51

1b.sdf (50)
1 2 3 4 5 6 7 8 9 10 11 12 13 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51

After each change, an image is generated highlighting the new alignment group atoms.

Finally, we will generate a molecular system for free energy calculations based on user-specified parameters and preprocessed results. The following arguments are available for the method:

  • margin (float): Water box margin for the system in Å. (default: 10)

  • ion_type (str): Type of ions to use. (default: "kcl")

  • ion_conc (float): Ion concentration. (default: 0.15) Ignored when ion_neutralize is True.

  • ion_neutralize (bool): Add only the counter ions needed to neutralize the system. (default: False)

  • use_hmr (bool): Whether to use hydrogen mass repartitioning. (default: False)

  • temperature (float): Temperature for the system in Kelvin. (default: 310.15)

The available options for ions are as follows:

  • ions: ['kcl', 'nacl', 'cacl2']

afes.generate_system()
afes.download_project(filename="afes.tar.gz")

Absolute Binding

Absolute binding has no morph sets — the ligands are processed directly, and step 3 needs Boresch restraints: three receptor–ligand atom pairs per ligand that hold the ligand in the pocket (they pin the six degrees of freedom).

afes = molcube.create_afes_project()
afes.create_project(
    title='my_abfe_project',
    reference_project_id=solution_project_id,
    calculate_application=Application.ABSOLUTE_BINDING,
    calculate_program=Program.AMBER,      # AMBER, GROMACS or OpenMM
)
afes.read_ligand_modeler_project(lrmbuilder.projectId)

# Step 2 — no morph set, ligands are processed directly
afes.processing_ligand(
    ligand_ff=[LigandForceField.OPENFF_FAST],
    selected_ligands={LigandForceField.OPENFF_FAST: ['1a.sdf', '1b.sdf']},
)

# Step 3 — Boresch restraints
afes.get_closest_atoms(lig_ff=LigandForceField.OPENFF_FAST, ligand_name='1a')
afes.apply_force_constant(10, 100, 100)
afes.generate_system()
  • afes.get_closest_atoms() seeds three receptor–ligand pairs per ligand and prints them as a table. The RESIDUE(p) and ATOM(l) columns are the values the editing methods take.

  • afes.get_distance() reports the geometry of the current pairs.

  • afes.add_boresh_restraint() adds a pair. receptor_info needs chainIndex, residueName and residueId:

    receptor_info = {'chainIndex': 'PROT_B', 'residueName': 'VAL', 'residueId': 231}
    afes.add_boresh_restraint(
        lig_ff=LigandForceField.OPENFF_FAST,
        ligand_name='1a',
        receptor_info=receptor_info,
        ligand_atom_name='C11x',
    )
    
  • afes.delete_boresh_restraint() removes pairs by index: delete_indices=[3].

  • afes.apply_force_constant() sets the distance / angle / dihedral force constants.

Warning

Every ligand must end up with exactly three pairs. get_closest_atoms() seeds three, so adding one without deleting another leaves that ligand unbalanced and generate_system() refuses to submit, naming the ligand and its count.

Mutation Free Energy

Mutation F.E. has neither morph sets nor restraints. Instead you declare which chains are the binding partner and which residues are mutated.

afes = molcube.create_afes_project()
afes.create_project(
    title='my_mutation_project',
    reference_project_id=solution_project_id,
    calculate_application=Application.MUTATION_FE,
    calculate_program=Program.AMBER,      # AMBER, GROMACS or BLaDE
)

# Binding partner chain(s) — a single chain or several
afes.set_target_chain(['PROT_A', 'PROT_B'])

# One mutation per site
afes.set_mutation({'chainIndex': 'PROT_C', 'resid': 20, 'mutation': 'VAL'})

afes.generate_system()

BLaDE MSλD evaluates several candidate residues at one site in a single simulation, so mutation may be a list:

afes.set_mutation({'chainIndex': 'PROT_B', 'resid': 20, 'mutation': ['VAL', 'SER', 'ALA']})

The candidates can also be built up over several calls with merge=True. Without it a repeated chain+resid is refused, since that is more often a mistyped resid than an intent to add candidates:

afes.set_mutation({'chainIndex': 'PROT_B', 'resid': 20, 'mutation': 'VAL'})
afes.set_mutation({'chainIndex': 'PROT_B', 'resid': 20, 'mutation': 'SER'}, merge=True)
# -> to == ['VAL', 'SER']   (targets already present are ignored)

Note

Multiple targets and merge=True are BLaDE-only — AMBER and GROMACS allow one amino acid per site and reject both.

Mutation F.E. cannot use the PDB Reader quick-build path; reference a finished Builder project instead.

BLaDE MSλD Relative Binding

BLaDE does not build ligand pairs. It groups ligands and evaluates a group at once, so generate_morph_set() is replaced by generate_ligand_group().

afes.create_project(
    title='my_blade_project',
    reference_project_id=solution_project_id,
    ff=ForceField.CHARMM,
    calculate_application=Application.RELATIVE_BINDING,
    calculate_program=Program.BLADE,
)
afes.read_ligand_modeler_project(lrmbuilder.projectId)

afes.generate_ligand_group(
    ligand_ff=[LigandForceField.GAFF_FAST],
    selected_ligands={LigandForceField.GAFF_FAST: ['1a.sdf', '1b.sdf', '1c.sdf']},
)
afes.set_ligand_group(LigandForceField.GAFF_FAST, n_groups=1, max_rsub_count=10)
afes.processing_ligand()
afes.get_core_indices(LigandForceField.GAFF_FAST, '1a', group_index=0)
afes.generate_system()

Membrane quick-build

With builder_type=BuilderType.MEMBRANE the bilayer is built inside the AFES project, so the lipid composition is given at project creation.

afes.create_project(
    title='my_membrane_afes',
    pdb_project_id=pdbreader.projectId,
    builder_type=BuilderType.MEMBRANE,
    box_margin=20,
    lipids=[
        {'lipid': 'CHL', 'upRatio': 1, 'lowRatio': 1},
        {'lipid': 'POPC', 'upRatio': 4, 'lowRatio': 4},
    ],
    ff=ForceField.AMBER,
)

One dict per lipid. upRatio / lowRatio are the composition ratios of the upper and lower leaflet — the web’s shorthand upper -> chl:popc=1:4 becomes the two entries above.

area (area per lipid, Ų) and type are filled in automatically:

  • area comes from the backend’s lipid library, which is also browsable:

    >>> afes.get_available_lipids()['POPC']
    {'area': 68.3, 'charge': 0, 'name': 'POPC', 'tailinfo': '16:0 / 18:1', 'thickness': 19}
    
  • type defaults to "standard". Special lipids (glycolipid, pegl, lps, lip) need it set explicitly along with their own fields.

Pass either value yourself to override the lookup. area decides how many lipids fit in the box, so a guessed value changes the system without failing.