Solvation plays a critical role in determining the structural, thermodynamic, and dynamical properties of molecules in solution. Accurately representing the solvent environment is therefore essential for preparing realistic simulation systems and for computing solution-phase properties such as free energies of solvation.
VeloxChem provides the SolvationBuilder class to construct solvated simulation boxes ready for molecular dynamics. Starting from a solute molecule and its force field topology, a periodic simulation box can be filled with solvent molecules — by default SPC/E water — with optional NPT equilibration and charge neutralization. For more complex environments, mixed solvents with user-defined proportions and box dimensions are also supported.
Beyond system preparation, VeloxChem offers the SolvationFepDriver class to compute free energies of solvation via free energy perturbation (FEP). By alchemically decoupling the solute from the solvent across a series of lambda states, the solvation free energy can be rigorously estimated from the resulting thermodynamic cycle.
Building systems¶
VeloxChem can be used to solvate system in preparation for molecular dynamics simulations. First, create a molecule object for the solute, in our example we choose deprotonated ibuprofen.
import veloxchem as vlx
solute = vlx.Molecule.read_smiles("CC(C)CC1=CC=C(C=C1)C(C)C(=O)[O-]")
solute.show()Second, generate a force field for the solute. By default RESP charges will be computed but, here, we instead make use of semi-empirical partial charges for faster execution.
ff_gen = vlx.MMForceFieldGenerator()
ff_gen.create_topology(solute)* Info * Using 6-31G* basis set for RESP charges...
* Info * Sum of partial charges is not a whole number.
* Info * Compensating by removing -3.000e-06 from the largest charge.
* Info * Using GAFF (v2.11) parameters.
Reference: J. Wang, R. M. Wolf, J. W. Caldwell, P. A. Kollman, D. A. Case, J. Comput. Chem. 2004,
25, 1157-1174.
* Info * Updated bond length 13-15 (c -o ) to 0.139 nm
* Info * Updated bond angle 14-13-15 (o -c -o ) to 119.379 deg
Third, we use of the SolvationBuilder class to create a simulation box with a solute padding 1.0 nm (default) consisting of SPC/E water (default). The solvator will run an NPT equilibration for 5 ps at 300 K.
solvator = vlx.SolvationBuilder()
solvator.solvate(solute, equilibrate=False, neutralize=False) VeloxChem Solvation Builder
=============================
* Info * Solvating the solute with cspce molecules
* Info * Padding: 1.0 nm
* Info * The box size is: 2.79 x 2.79 x 2.79 nm^3
* Info * The volume of the solute is: 0.23 nm^3
* Info * The volume available for the solvent is: 21.43 nm^3
* Info * The experimental density of cspce is: 1000 kg/m^3
* Info * Solvated system with 713 solvent molecules out of 713 requested
* Info * Time to solvate the system: 0.35 s
* Info * The density of the solvent after packing is: 994 kg/m^3
solvator.show_solvation_box()Mixed solvents¶
Solvents can be mixed. Molecule objects are created for each type of solvent molecules.
water = vlx.Molecule.read_smiles("O")
propylene_glycol = vlx.Molecule.read_smiles("CC(CO)O")Let us consider a solvation with a 50/50 mix of number of water and propylene glycol molecules in the solvent.
solvator.custom_solvate(
solute,
solvents=[water, propylene_glycol],
proportion=(50, 50),
box_size=(25, 25, 25),
)* Info * Solvated system with 70 solvent molecules out of 70 requested
* Info * Warning: 90 attempts have been made to insert the solvent molecule
* Info * Consider reducing the target density
* Info * Solvated system with 70 solvent molecules out of 70 requested
solvator.show_solvation_box()Add saving files options.
Free energy of solvation¶
fep_drv = vlx.SolvationFepDriver()
# Settings are here chosen for a quick execution,
# it is recommended to use the default settings
fep_drv.num_em_steps = 500
fep_drv.num_equil_steps = 500
fep_drv.num_steps = 500
# Pre-equilibrate the solvation box
solvator.perform_equilibration()
# Compute solvation free energy
fep_results = fep_drv.compute_solvation_free_energy(ff_gen, solvator)* Info * The box size after equilibration is: 2.30 x 2.30 x 2.30 nm^3
* Info * The density of the solvent after equilibration is: 176 kg/m^3
* Info * Generating the ForceField for the solvent
* Info * Generating the ForceField for the solvent
* Info * solute.itp file written
* Info * solvent_1.itp file written
* Info * solvent_2.itp file written
* Info * system.top file written
* Info * system.gro file written
VeloxChem/OpenMM Solvation Free Energy Calculation
==================================================
Simulation parameters:
----------------------
Temperature: 298.15 K
Pressure: 1 atm
Timestep: 2.0 fs
Non-Bonded Cutoff: 1.0 nm
Thermodynamic Ensemble: NPT
Alchemical Parameters:
----------------------
Number of equilibration steps: 500
Number of steps per lambda simulation: 500
Number of snapshots per lambda simulation: 500
Simulation time per lambda: 0.00 ns
Lambdas in Stage 1: [0.0, 0.2, 0.4, 0.6, 0.8, 1.0]
Lambdas in Stage 2: [1.0, 0.8, 0.6, 0.4, 0.3, 0.2, 0.15, 0.1, 0.05, 0.03, 0.0]
Lambdas in Stage 3: [0.0, 0.2, 0.4, 0.6, 0.8, 1.0]
Lambdas in Stage 4: [1.0, 0.5, 0.0]
* Info * Starting solvated simulation (Stage 1)...
* Info * Generating systems for stage 1
* Info * Running lambda = 0.0, stage = 1...
* Info * Time spent in energy minimization: 0.40 s
* Info * Time spent in pre-equilibration: 0.06 s
* Info * Equilibration detected at frame 378 with Neff_max = 65.36
* Info * Frames saved = 122 | No subsampling (g=1.88 <= 20)
* Info * Lambda = 0.0 completed. Elapsed time: 0.75 s
* Info * Performance: 4.79 ns/hour
* Info * Running lambda = 0.2, stage = 1...
* Info * Time spent in energy minimization: 0.39 s
* Info * Time spent in pre-equilibration: 0.06 s
* Info * Equilibration detected at frame 447 with Neff_max = 18.95
* Info * Frames saved = 53 | No subsampling (g=2.85 <= 20)
* Info * Lambda = 0.2 completed. Elapsed time: 0.81 s
* Info * Performance: 4.44 ns/hour
* Info * Running lambda = 0.4, stage = 1...
* Info * Time spent in energy minimization: 0.38 s
* Info * Time spent in pre-equilibration: 0.05 s
* Info * Equilibration detected at frame 432 with Neff_max = 25.79
* Info * Frames saved = 68 | No subsampling (g=2.68 <= 20)
* Info * Lambda = 0.4 completed. Elapsed time: 0.72 s
* Info * Performance: 4.97 ns/hour
* Info * Running lambda = 0.6, stage = 1...
* Info * Time spent in energy minimization: 0.36 s
* Info * Time spent in pre-equilibration: 0.06 s
* Info * Equilibration detected at frame 391 with Neff_max = 42.07
* Info * Frames saved = 109 | No subsampling (g=2.61 <= 20)
* Info * Lambda = 0.6 completed. Elapsed time: 0.58 s
* Info * Performance: 6.23 ns/hour
* Info * Running lambda = 0.8, stage = 1...
* Info * Time spent in energy minimization: 0.40 s
* Info * Time spent in pre-equilibration: 0.05 s
* Info * Equilibration detected at frame 487 with Neff_max = 14.00
* Info * Frames saved = 13 | No subsampling (g=1.00 <= 20)
* Info * Lambda = 0.8 completed. Elapsed time: 0.76 s
* Info * Performance: 4.74 ns/hour
* Info * Running lambda = 1.0, stage = 1...
* Info * Time spent in energy minimization: 0.41 s
* Info * Time spent in pre-equilibration: 0.05 s
* Info * Equilibration detected at frame 484 with Neff_max = 16.98
* Info * Frames saved = 16 | No subsampling (g=1.00 <= 20)
* Info * Lambda = 1.0 completed. Elapsed time: 0.64 s
* Info * Performance: 5.66 ns/hour
* Info * Total simulation time for stage 1: 4.26 s. Total simulated time: 0.01 ns.
* Info * Overall performance for stage 1: 5.07 ns/hour
* Info * Recalculating energies for stage 1...
* Info * Recalculating energies for Forcefield 0...
* Info * Forcefield 0 energy recalculation took 0.38 seconds.
* Info * Recalculating energies for Forcefield 1...
* Info * Forcefield 1 energy recalculation took 0.41 seconds.
* Info * Recalculating energies for Forcefield 2...
* Info * Forcefield 2 energy recalculation took 0.41 seconds.
* Info * Recalculating energies for Forcefield 3...
* Info * Forcefield 3 energy recalculation took 0.40 seconds.
* Info * Recalculating energies for Forcefield 4...
* Info * Forcefield 4 energy recalculation took 0.41 seconds.
* Info * Recalculating energies for Forcefield 5...
* Info * Forcefield 5 energy recalculation took 0.52 seconds.
* Info * Energy recalculation for stage 1 took 2.56 seconds.
* Info * Calculating the free energy with MBAR for stage 1...
******* JAX 64-bit mode is now on! *******
* JAX is now set to 64-bit mode! *
* This MAY cause problems with other *
* uses of JAX in the same code. *
******************************************
Free energy for stage 1: -230.3150 +/- 1.3111 kJ/mol
* Info * Removing GSC potential (Stage 2)...
* Info * Generating systems for stage 2
* Info * Running lambda = 1.0, stage = 2...
* Info * Time spent in energy minimization: 0.29 s
* Info * Time spent in pre-equilibration: 0.06 s
* Info * Equilibration detected at frame 485 with Neff_max = 16.00
* Info * Frames saved = 15 | No subsampling (g=1.00 <= 20)
* Info * Lambda = 1.0 completed. Elapsed time: 0.61 s
* Info * Performance: 5.93 ns/hour
* Info * Running lambda = 0.8, stage = 2...
* Info * Time spent in energy minimization: 0.33 s
* Info * Time spent in pre-equilibration: 0.05 s
* Info * Equilibration detected at frame 418 with Neff_max = 24.83
* Info * Frames saved = 82 | No subsampling (g=3.34 <= 20)
* Info * Lambda = 0.8 completed. Elapsed time: 0.83 s
* Info * Performance: 4.34 ns/hour
* Info * Running lambda = 0.6, stage = 2...
* Info * Time spent in energy minimization: 0.38 s
* Info * Time spent in pre-equilibration: 0.05 s
* Info * Equilibration detected at frame 483 with Neff_max = 18.00
* Info * Frames saved = 17 | No subsampling (g=1.00 <= 20)
* Info * Lambda = 0.6 completed. Elapsed time: 0.66 s
* Info * Performance: 5.44 ns/hour
* Info * Running lambda = 0.4, stage = 2...
* Info * Time spent in energy minimization: 0.36 s
* Info * Time spent in pre-equilibration: 0.06 s
* Info * Equilibration detected at frame 332 with Neff_max = 26.33
* Info * Frames saved = 168 | No subsampling (g=6.42 <= 20)
* Info * Lambda = 0.4 completed. Elapsed time: 0.68 s
* Info * Performance: 5.27 ns/hour
* Info * Running lambda = 0.3, stage = 2...
* Info * Time spent in energy minimization: 0.36 s
* Info * Time spent in pre-equilibration: 0.05 s
* Info * Equilibration detected at frame 364 with Neff_max = 43.40
* Info * Frames saved = 136 | No subsampling (g=3.16 <= 20)
* Info * Lambda = 0.3 completed. Elapsed time: 0.59 s
* Info * Performance: 6.07 ns/hour
* Info * Running lambda = 0.2, stage = 2...
* Info * Time spent in energy minimization: 0.34 s
* Info * Time spent in pre-equilibration: 0.05 s
* Info * Equilibration detected at frame 369 with Neff_max = 38.17
* Info * Frames saved = 131 | No subsampling (g=3.46 <= 20)
* Info * Lambda = 0.2 completed. Elapsed time: 0.58 s
* Info * Performance: 6.26 ns/hour
* Info * Running lambda = 0.15, stage = 2...
* Info * Time spent in energy minimization: 0.28 s
* Info * Time spent in pre-equilibration: 0.05 s
* Info * Equilibration detected at frame 457 with Neff_max = 15.34
* Info * Frames saved = 43 | No subsampling (g=2.87 <= 20)
* Info * Lambda = 0.15 completed. Elapsed time: 0.60 s
* Info * Performance: 5.95 ns/hour
* Info * Running lambda = 0.1, stage = 2...
* Info * Time spent in energy minimization: 0.34 s
* Info * Time spent in pre-equilibration: 0.05 s
* Info * Equilibration detected at frame 478 with Neff_max = 22.42
* Info * Frames saved = 22 | No subsampling (g=1.03 <= 20)
* Info * Lambda = 0.1 completed. Elapsed time: 0.63 s
* Info * Performance: 5.68 ns/hour
* Info * Running lambda = 0.05, stage = 2...
* Info * Time spent in energy minimization: 0.32 s
* Info * Time spent in pre-equilibration: 0.06 s
* Info * Equilibration detected at frame 404 with Neff_max = 28.92
* Info * Frames saved = 96 | No subsampling (g=3.35 <= 20)
* Info * Lambda = 0.05 completed. Elapsed time: 0.65 s
* Info * Performance: 5.53 ns/hour
* Info * Running lambda = 0.03, stage = 2...
* Info * Time spent in energy minimization: 0.36 s
* Info * Time spent in pre-equilibration: 0.06 s
* Info * Equilibration detected at frame 413 with Neff_max = 17.59
* Info * Frames saved = 87 | No subsampling (g=5.00 <= 20)
* Info * Lambda = 0.03 completed. Elapsed time: 0.52 s
* Info * Performance: 6.90 ns/hour
* Info * Running lambda = 0.0, stage = 2...
* Info * Time spent in energy minimization: 0.38 s
* Info * Time spent in pre-equilibration: 0.06 s
* Info * Equilibration detected at frame 429 with Neff_max = 20.48
* Info * Frames saved = 71 | No subsampling (g=3.52 <= 20)
* Info * Lambda = 0.0 completed. Elapsed time: 0.69 s
* Info * Performance: 5.20 ns/hour
* Info * Total simulation time for stage 2: 7.05 s. Total simulated time: 0.01 ns.
* Info * Overall performance for stage 2: 5.61 ns/hour
* Info * Recalculating energies for stage 2...
* Info * Recalculating energies for Forcefield 0...
* Info * Forcefield 0 energy recalculation took 0.78 seconds.
* Info * Recalculating energies for Forcefield 1...
* Info * Forcefield 1 energy recalculation took 0.81 seconds.
* Info * Recalculating energies for Forcefield 2...
* Info * Forcefield 2 energy recalculation took 0.90 seconds.
* Info * Recalculating energies for Forcefield 3...
* Info * Forcefield 3 energy recalculation took 0.79 seconds.
* Info * Recalculating energies for Forcefield 4...
* Info * Forcefield 4 energy recalculation took 0.80 seconds.
* Info * Recalculating energies for Forcefield 5...
* Info * Forcefield 5 energy recalculation took 0.81 seconds.
* Info * Recalculating energies for Forcefield 6...
* Info * Forcefield 6 energy recalculation took 0.84 seconds.
* Info * Recalculating energies for Forcefield 7...
* Info * Forcefield 7 energy recalculation took 0.83 seconds.
* Info * Recalculating energies for Forcefield 8...
* Info * Forcefield 8 energy recalculation took 1.01 seconds.
* Info * Recalculating energies for Forcefield 9...
* Info * Forcefield 9 energy recalculation took 0.79 seconds.
* Info * Recalculating energies for Forcefield 10...
* Info * Forcefield 10 energy recalculation took 0.79 seconds.
* Info * Energy recalculation for stage 2 took 9.17 seconds.
* Info * Calculating the free energy with MBAR for stage 2...
Free energy for stage 2: 102.4402 +/- 0.3866 kJ/mol
* Info * Starting vacuum simulation (Stage 3)...
* Info * Generating systems for stage 3
* Info * Running lambda = 0.0, stage = 3...
* Info * Time spent in energy minimization: 0.03 s
* Info * Time spent in pre-equilibration: 0.01 s
* Info * Equilibration detected at frame 399 with Neff_max = 41.27
* Info * Frames saved = 101 | No subsampling (g=2.47 <= 20)
* Info * Lambda = 0.0 completed. Elapsed time: 0.08 s
* Info * Performance: 42.57 ns/hour
* Info * Running lambda = 0.2, stage = 3...
* Info * Time spent in energy minimization: 0.01 s
* Info * Time spent in pre-equilibration: 0.01 s
* Info * Equilibration detected at frame 182 with Neff_max = 98.36
* Info * Frames saved = 318 | No subsampling (g=3.24 <= 20)
* Info * Lambda = 0.2 completed. Elapsed time: 0.09 s
* Info * Performance: 40.50 ns/hour
* Info * Running lambda = 0.4, stage = 3...
* Info * Time spent in energy minimization: 0.01 s
* Info * Time spent in pre-equilibration: 0.01 s
* Info * Equilibration detected at frame 0 with Neff_max = 145.11
* Info * Frames saved = 500 | No subsampling (g=3.45 <= 20)
* Info * Lambda = 0.4 completed. Elapsed time: 0.10 s
* Info * Performance: 37.67 ns/hour
* Info * Running lambda = 0.6, stage = 3...
* Info * Time spent in energy minimization: 0.03 s
* Info * Time spent in pre-equilibration: 0.01 s
* Info * Equilibration detected at frame 199 with Neff_max = 91.03
* Info * Frames saved = 301 | No subsampling (g=3.32 <= 20)
* Info * Lambda = 0.6 completed. Elapsed time: 0.09 s
* Info * Performance: 37.92 ns/hour
* Info * Running lambda = 0.8, stage = 3...
* Info * Time spent in energy minimization: 0.03 s
* Info * Time spent in pre-equilibration: 0.01 s
* Info * Equilibration detected at frame 302 with Neff_max = 72.51
* Info * Frames saved = 198 | No subsampling (g=2.74 <= 20)
* Info * Lambda = 0.8 completed. Elapsed time: 0.09 s
* Info * Performance: 39.77 ns/hour
* Info * Running lambda = 1.0, stage = 3...
* Info * Time spent in energy minimization: 0.02 s
* Info * Time spent in pre-equilibration: 0.01 s
* Info * Equilibration detected at frame 42 with Neff_max = 171.86
* Info * Frames saved = 458 | No subsampling (g=2.67 <= 20)
* Info * Lambda = 1.0 completed. Elapsed time: 0.10 s
* Info * Performance: 37.28 ns/hour
* Info * Total simulation time for stage 3: 0.55 s. Total simulated time: 0.01 ns.
* Info * Overall performance for stage 3: 39.20 ns/hour
* Info * Recalculating energies for stage 3...
* Info * Recalculating energies for Forcefield 0...
* Info * Forcefield 0 energy recalculation took 0.19 seconds.
* Info * Recalculating energies for Forcefield 1...
* Info * Forcefield 1 energy recalculation took 0.21 seconds.
* Info * Recalculating energies for Forcefield 2...
* Info * Forcefield 2 energy recalculation took 0.21 seconds.
* Info * Recalculating energies for Forcefield 3...
* Info * Forcefield 3 energy recalculation took 0.21 seconds.
* Info * Recalculating energies for Forcefield 4...
* Info * Forcefield 4 energy recalculation took 0.23 seconds.
* Info * Recalculating energies for Forcefield 5...
* Info * Forcefield 5 energy recalculation took 0.21 seconds.
* Info * Energy recalculation for stage 3 took 1.29 seconds.
* Info * Calculating the free energy with MBAR for stage 3...
Free energy for stage 3: 239.6142 +/- 0.0984 kJ/mol
* Info * Removing GSC potential in vacuum (Stage 4)...
* Info * Generating systems for stage 4
* Info * Running lambda = 1.0, stage = 4...
* Info * Time spent in energy minimization: 0.01 s
* Info * Time spent in pre-equilibration: 0.01 s
* Info * Equilibration detected at frame 390 with Neff_max = 58.29
* Info * Frames saved = 110 | No subsampling (g=1.90 <= 20)
* Info * Lambda = 1.0 completed. Elapsed time: 0.09 s
* Info * Performance: 41.02 ns/hour
* Info * Running lambda = 0.5, stage = 4...
* Info * Time spent in energy minimization: 0.01 s
* Info * Time spent in pre-equilibration: 0.01 s
* Info * Equilibration detected at frame 428 with Neff_max = 46.98
* Info * Frames saved = 72 | No subsampling (g=1.55 <= 20)
* Info * Lambda = 0.5 completed. Elapsed time: 0.09 s
* Info * Performance: 40.86 ns/hour
* Info * Running lambda = 0.0, stage = 4...
* Info * Time spent in energy minimization: 0.01 s
* Info * Time spent in pre-equilibration: 0.01 s
* Info * Equilibration detected at frame 5 with Neff_max = 136.37
* Info * Frames saved = 495 | No subsampling (g=3.64 <= 20)
* Info * Lambda = 0.0 completed. Elapsed time: 0.08 s
* Info * Performance: 43.33 ns/hour
* Info * Total simulation time for stage 4: 0.26 s. Total simulated time: 0.00 ns.
* Info * Overall performance for stage 4: 41.71 ns/hour
* Info * Recalculating energies for stage 4...
* Info * Recalculating energies for Forcefield 0...
* Info * Forcefield 0 energy recalculation took 0.10 seconds.
* Info * Recalculating energies for Forcefield 1...
* Info * Forcefield 1 energy recalculation took 0.12 seconds.
* Info * Recalculating energies for Forcefield 2...
* Info * Forcefield 2 energy recalculation took 0.12 seconds.
* Info * Energy recalculation for stage 4 took 0.36 seconds.
* Info * Calculating the free energy with MBAR for stage 4...
Free energy for stage 4: 20.3623 +/- 0.3692 kJ/mol
Final free energy: -387.8512 kJ/mol
print(f'Solvation free energy: {fep_results["free_energy"]:.3f} kJ/mol')Solvation free energy: -387.851 kJ/mol