System setup

Packmol Input Creator

This module helps the setup of a Packmol input file, by computing the number of molecules and sizes necessary to build different systems. Currently (as of version 1.27.0) the module supports the construction of systems of a solute (macromolecule for example) solvated by a a single solvent or a mixture of two solvents.

How to use it

julia> using MolSimToolkit.PackmolInputCreator

Running Packmol

Packmol can be run directly from within Julia using the Packmol Julia package:

using Packmol
run_packmol("./box.inp")

If everything runs correctly, the output PDB file of the system will be created.

Solute-Solvent system

Here, SolutionBoxUS stands for Solute (U) and Solvent (S). The density of the solvent can be one of "g/mL" or "mol/L" (molarity).

MolSimToolkit.PackmolInputCreator.SolutionBoxUSType
SolutionBoxUS(; 
    solute_pdbfile::String, 
    solvent_pdbfile::String,
    density::Float64,
    density_units = "g/mL",
    solute_molar_mass = nothing, # optional
    solvent_molar_mass = nothing, # optional
)

Setup a system composed of a solute (U) and a solvent (S).

The mass or molar density can be provided, and the units are either "g/mL" or "mol/L". The default is "g/mL".

The molar masses of the solute and solvent can be provided manually. If not, they will be computed from the atom types in the PDB file.

source
MolSimToolkit.PackmolInputCreator.write_packmol_inputMethod
write_packmol_input(
    system::SolutionBoxUS;
    input="box.inp",
    output="system.pdb",
    # box size
    box_sides::AbstractVector{<:Real}, # or
    margin::Real,
    cubic::Bool = false,
)

Function that generates an input file for Packmol for a Solute + Solvent system.

The box sides are given in Ångströms, and can be provided as a vector of 3 elements. Alternativelly, the margin can be provided, and the box sides will be calculated as the maximum and minimum coordinates of the solute plus the margin in all 3 dimensions.

If cubic is set to true, the box will be cubic, and the box sides will be equal in all 3 dimensions, respecting the minimum margin provided.

source

Setting up the system properties

We initialize the system data structure, given the PDB files of one molecule of the polymer (poly_h.pdb), and one molecule of water:

# Directory of test files
test_dir = MolSimToolkit.PackmolInputCreator.PackmolInputCreatorDirectory*"/test"
# Construction of system data structure
system = SolutionBoxUSC(
    solute_pdbfile = "$test_dir/data/poly_h.pdb",
    solvent_pdbfile = "$test_dir/data/water.pdb",
    density = 1.0,
    density_units = "g/mL",
    solute_molar_mass = nothing, # optional
    solvent_molar_mass = nothing, # optional
)

The molar masses of the components can be provided explicitly by the user. If not, they will be computed from the atom types in the PDB files, but this may fail if the mass of some atom type is unknown.

Finally, we can generate an input file for Packmol with:

write_packmol_input(
    system; 
    margin = 20.0, 
    cubic = true,
    input = "box.inp",
    output = "system.pdb"
)

The input parameter provides the name of the input file for Packmol that will be generated.

The margin parameter sets the size of the box, which will take into consideration the maximum and minimum dimensions of the solute. If cubic is set to true the box will be cubic, otherwise it will be orthorhombic but with different length in each direction, respecting the margin provided.

Alternatively, the size of the box can be provided explicitly with the box_sides = [ a, b, c ] parameters, where a, b, and c are the lengths of the box in each dimension.

Solute-Solvent-Cossolvent system

Here, SolutionBoxUSC stands for Solute (U), Solvent (S), and Cossolvent (C). The concentration units can be one of "mol/L" (molarity), "x" (molar fraction), "vv" (volume fraction), and "mm" (mass fraction). The density is assumed to be in g/mL.

MolSimToolkit.PackmolInputCreator.SolutionBoxUSCType
SolutionBoxUSC(; 
    solute_pdbfile::String, 
    solvent_pdbfile::String,
    cossolvent_pdbfile::String,
    density_table::Matrix{Float64},
    concentration_units = "x",
    solute_molar_mass = nothing, # optional
    solvent_molar_mass = nothing, # optional
    cossolvent_molar_mass = nothing, # optional
)

Setup a system composed of a solute (U) a solvent (S) and a cossolvent (C).

The concentration units of the density table can be provided explicitly and are assumed by default to be the molar fraction, x, of the cossolvent.

The molar masses of the solute, solvent, and cossolvent can be provided manually. If not, they will be computed from the atom types in the PDB file.

source
MolSimToolkit.PackmolInputCreator.write_packmol_inputMethod
write_packmol_input(
    system::SolutionBoxUSC;
    concentration::Real, 
    input="box.inp",
    output="system.pdb",
    # box size
    box_sides::AbstractVector{<:Real}, # or
    margin::Real,
    cubic::Bool = false,
)

Function that generates an input file for Packmol.

The box sides are given in Ångströms, and can be provided as a vector of 3 elements. Alternativelly, the margin can be provided, and the box sides will be calculated as the maximum and minimum coordinates of the solute plus the margin in all 3 dimensions.

If cubic is set to true, the box will be cubic, and the box sides will be equal in all 3 dimensions, respecting the minimum margin provided.

source
MolSimToolkit.PackmolInputCreator.convert_concentrationFunction
convert_concentration(
    system::SolutionBoxUSC,
    input_concentration, 
    units
)

Convert concentration from one unit to another. The input concentration is given in input_concentration, and the unit conversion is given by units keyword, that can be one of the following pairs:

The supported concentration units are:

  • "mol/L": molarity
  • "x": molar fraction
  • "vv": volume fraction
  • "mm": mass fraction

Conversion among types consists in passing the units keyword argument, which is a pair of the form "from" => "to", where "from" and "to" are one of the supported units.

Example

For example, to convert from molarity to molar fraction, use:

convert_concentration(system, 55.5, "mol/L" => "x")

where system is a SolutionBoxUSC object, and 55.5 is the molarity.

source
MolSimToolkit.PackmolInputCreator.convert_density_table!Function
convert_density_table!(system::SolutionBoxUSC, target_units)

Converts the density table of the system from one unit to another. Returns the input system with the density table converted to the new units.

The target units may be one of: "mol/L", "x", "vv", "mm".

Example

convert_density_table!(system, "mol/L")
source

Setting up the system properties

Here, we setup a system of a polymer solvated by water and ethanol. The densities as a function of the molar fraction of ethanol are available in a data table:

density_table = [
# x cossolvent (ethanol)     density (g/mL)
         0.0000                 0.9981
         0.0416                 0.9820
         0.0890                 0.9685
         0.1434                 0.9537
         0.2066                 0.9369
         0.2809                 0.9151
         0.3695                 0.8923
         0.4769                 0.8685
         0.6098                 0.8450
         0.7786                 0.8195
         1.0000                 0.7906
]

Next, we initialize the system data structure, given the PDB files of one molecule of the polymer (poly_h.pdb), and one molecule of water and ethanol:

# Directory of test files
test_dir = MolSimToolkit.PackmolInputCreator.PackmolInputCreatorDirectory*"/test"
# Construction of system data structure
system = SolutionBoxUSC(
    solute_pdbfile = "$test_dir/data/poly_h.pdb",
    solvent_pdbfile = "$test_dir/data/water.pdb",
    cossolvent_pdbfile = "$test_dir/data/ethanol.pdb",
    density_table = density_table,
    concentration_units = "x", # molar fraction
    solute_molar_mass = nothing, # optional
    solvent_molar_mass = nothing, # optional
    cossolvent_molar_mass = nothing, # optional
)

The molar masses of the components can be provided explicitly by the user. If not, they will be computed from the atom types in the PDB files, but this may fail if the mass of some atom type is unknown.

Tip

The density table can be converted among different units with the function convert_density_table!, which acts on the SystemBox object. For example:

julia> convert_density_table!(system, "mol/L")

Finally, we can generate an input file for Packmol with:

write_packmol_input(
    system; 
    concentration = 0.5,
    margin = 20.0, 
    cubic = true,
    input = "box.inp",
    output = "system.pdb"
)

The concentration can be given in molar fraction (x), molarity (mol/L), or volume fraction (vv).

The input parameter provides the name of the input file for Packmol that will be generated.

The margin parameter sets the size of the box, which will take into consideration the maximum and minimum dimensions of the solute. If cubic is set to true the box will be cubic, otherwise it will be orthorhombic but with different length in each direction, respecting the margin provided.

Alternatively, the size of the box can be provided explicitly with the box_sides = [ a, b, c ] parameters, where a, b, and c are the lengths of the box in each dimension.