Skip to content

Commit

Permalink
Merge pull request #210 from OpenBioSim/feature_ion_template
Browse files Browse the repository at this point in the history
Add function to create ions from AMBER templates
  • Loading branch information
lohedges authored Jul 11, 2024
2 parents 633590a + a742357 commit 3c890c3
Show file tree
Hide file tree
Showing 7 changed files with 706 additions and 0 deletions.
62 changes: 62 additions & 0 deletions corelib/src/libs/SireIO/biosimspace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1589,6 +1589,68 @@ namespace SireIO
return retval;
}

Molecule createSodiumIon(const Vector &coords, const QString model, const PropertyMap &map)
{
// Strip all whitespace from the model name and convert to upper case.
auto _model = model.simplified().replace(" ", "").toUpper();

// Create a hash between the allowed model names and their templace files.
QHash<QString, QString> models;
models["TIP3P"] = getShareDir() + "/templates/ions/na_tip3p";
models["TIP4P"] = getShareDir() + "/templates/ions/na_tip4p";

// Make sure the user has passed a valid water model.
if (not models.contains(_model))
{
throw SireError::incompatible_error(QObject::tr("Unsupported AMBER ion model '%1'").arg(model), CODELOC);
}

// Extract the water model template path.
auto path = models[_model];

// Load the ion template.
auto ion_template = MoleculeParser::read(path + ".prm7", map);

// Extract the ion the template.
auto ion = ion_template[MolIdx(0)].molecule();

// Set the coordinates of the ion.
ion = ion.edit().atom(AtomIdx(0)).setProperty(map["coordinates"], coords).molecule().commit();

return ion;
}

Molecule createChlorineIon(const Vector &coords, const QString model, const PropertyMap &map)
{
// Strip all whitespace from the model name and convert to upper case.
auto _model = model.simplified().replace(" ", "").toUpper();

// Create a hash between the allowed model names and their templace files.
QHash<QString, QString> models;
models["TIP3P"] = getShareDir() + "/templates/ions/cl_tip3p";
models["TIP4P"] = getShareDir() + "/templates/ions/cl_tip4p";

// Make sure the user has passed a valid water model.
if (not models.contains(_model))
{
throw SireError::incompatible_error(QObject::tr("Unsupported AMBER ion model '%1'").arg(model), CODELOC);
}

// Extract the water model template path.
auto path = models[_model];

// Load the ion template.
auto ion_template = MoleculeParser::read(path + ".prm7");

// Extract the ion the template.
auto ion = ion_template[MolIdx(0)].molecule();

// Set the coordinates of the ion.
ion = ion.edit().atom(AtomIdx(0)).setProperty(map["coordinates"], coords).molecule().commit();

return ion;
}

Vector cross(const Vector &v0, const Vector &v1)
{
double nx = v0.y() * v1.z() - v0.z() * v1.y();
Expand Down
34 changes: 34 additions & 0 deletions corelib/src/libs/SireIO/biosimspace.h
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,38 @@ namespace SireIO
const QHash<MolIdx, MolIdx> &molecule_mapping, const bool is_lambda1 = false,
const PropertyMap &map0 = PropertyMap(), const PropertyMap &map1 = PropertyMap());

//! Create a sodium ion at the specified position.
/*! \param position
The position of the sodium ion.
\param model
The name of the water model.
\param map
A dictionary of user-defined molecular property names.
\retval sodium
The sodium ion.
*/
SIREIO_EXPORT Molecule createSodiumIon(
const Vector &coords, const QString model, const PropertyMap &map = PropertyMap());

//! Create a chlorine ion at the specified position.
/*! \param position
The position of the chlorine ion.
\param model
The name of the water model.
\param map
A dictionary of user-defined molecular property names.
\retval chlorine
The chlorine ion.
*/
SIREIO_EXPORT Molecule createChlorineIon(
const Vector &coords, const QString model, const PropertyMap &map = PropertyMap());

Vector cross(const Vector &v0, const Vector &v1);
} // namespace SireIO

Expand All @@ -332,6 +364,8 @@ SIRE_EXPOSE_FUNCTION(SireIO::setAmberWater)
SIRE_EXPOSE_FUNCTION(SireIO::setGromacsWater)
SIRE_EXPOSE_FUNCTION(SireIO::updateAndPreserveOrder)
SIRE_EXPOSE_FUNCTION(SireIO::updateCoordinatesAndVelocities)
SIRE_EXPOSE_FUNCTION(SireIO::createSodiumIon)
SIRE_EXPOSE_FUNCTION(SireIO::createChlorineIon)

SIRE_END_HEADER

Expand Down
130 changes: 130 additions & 0 deletions corelib/templates/ions/cl_tip3p.prm7
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
%VERSION VERSION_STAMP = V0001.000 DATE = 07/10/24 14:04:15
%FLAG TITLE
%FORMAT(20a4)

%FLAG POINTERS
%FORMAT(10I8)
1 1 0 0 0 0 0 0 0 0
1 1 0 0 0 0 0 0 1 0
0 0 0 0 0 0 0 0 1 0
0 0 0
%FLAG ATOM_NAME
%FORMAT(20a4)
Cl-
%FLAG CHARGE
%FORMAT(5E16.8)
-1.82223000E+01
%FLAG ATOMIC_NUMBER
%FORMAT(10I8)
17
%FLAG MASS
%FORMAT(5E16.8)
3.54500000E+01
%FLAG ATOM_TYPE_INDEX
%FORMAT(10I8)
1
%FLAG NUMBER_EXCLUDED_ATOMS
%FORMAT(10I8)
1
%FLAG NONBONDED_PARM_INDEX
%FORMAT(10I8)
1
%FLAG RESIDUE_LABEL
%FORMAT(20a4)
Cl-
%FLAG RESIDUE_POINTER
%FORMAT(10I8)
1
%FLAG BOND_FORCE_CONSTANT
%FORMAT(5E16.8)

%FLAG BOND_EQUIL_VALUE
%FORMAT(5E16.8)

%FLAG ANGLE_FORCE_CONSTANT
%FORMAT(5E16.8)

%FLAG ANGLE_EQUIL_VALUE
%FORMAT(5E16.8)

%FLAG DIHEDRAL_FORCE_CONSTANT
%FORMAT(5E16.8)

%FLAG DIHEDRAL_PERIODICITY
%FORMAT(5E16.8)

%FLAG DIHEDRAL_PHASE
%FORMAT(5E16.8)

%FLAG SCEE_SCALE_FACTOR
%FORMAT(5E16.8)

%FLAG SCNB_SCALE_FACTOR
%FORMAT(5E16.8)

%FLAG SOLTY
%FORMAT(5E16.8)
0.00000000E+00
%FLAG LENNARD_JONES_ACOEF
%FORMAT(5E16.8)
9.24719470E+06
%FLAG LENNARD_JONES_BCOEF
%FORMAT(5E16.8)
1.14737423E+03
%FLAG BONDS_INC_HYDROGEN
%FORMAT(10I8)

%FLAG BONDS_WITHOUT_HYDROGEN
%FORMAT(10I8)

%FLAG ANGLES_INC_HYDROGEN
%FORMAT(10I8)

%FLAG ANGLES_WITHOUT_HYDROGEN
%FORMAT(10I8)

%FLAG DIHEDRALS_INC_HYDROGEN
%FORMAT(10I8)

%FLAG DIHEDRALS_WITHOUT_HYDROGEN
%FORMAT(10I8)

%FLAG EXCLUDED_ATOMS_LIST
%FORMAT(10I8)
0
%FLAG HBOND_ACOEF
%FORMAT(5E16.8)

%FLAG HBOND_BCOEF
%FORMAT(5E16.8)

%FLAG HBCUT
%FORMAT(5E16.8)

%FLAG AMBER_ATOM_TYPE
%FORMAT(20a4)
Cl-
%FLAG TREE_CHAIN_CLASSIFICATION
%FORMAT(20a4)
M
%FLAG JOIN_ARRAY
%FORMAT(10I8)
0
%FLAG IROTAT
%FORMAT(10I8)
0
%FLAG RADIUS_SET
%FORMAT(1a80)
modified Bondi radii (mbondi)
%FLAG RADII
%FORMAT(5E16.8)
1.70000000E+00
%FLAG SCREEN
%FORMAT(5E16.8)
8.00000000E-01
%FLAG ATOMS_PER_MOLECULE
%FORMAT(10I8)
1
%FLAG IPOL
%FORMAT(1I8)
0
130 changes: 130 additions & 0 deletions corelib/templates/ions/cl_tip4p.prm7
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
%VERSION VERSION_STAMP = V0001.000 DATE = 07/10/24 14:04:34
%FLAG TITLE
%FORMAT(20a4)

%FLAG POINTERS
%FORMAT(10I8)
1 1 0 0 0 0 0 0 0 0
1 1 0 0 0 0 0 0 1 0
0 0 0 0 0 0 0 0 1 0
0 0 0
%FLAG ATOM_NAME
%FORMAT(20a4)
Cl-
%FLAG CHARGE
%FORMAT(5E16.8)
-1.82223000E+01
%FLAG ATOMIC_NUMBER
%FORMAT(10I8)
17
%FLAG MASS
%FORMAT(5E16.8)
3.54500000E+01
%FLAG ATOM_TYPE_INDEX
%FORMAT(10I8)
1
%FLAG NUMBER_EXCLUDED_ATOMS
%FORMAT(10I8)
1
%FLAG NONBONDED_PARM_INDEX
%FORMAT(10I8)
1
%FLAG RESIDUE_LABEL
%FORMAT(20a4)
Cl-
%FLAG RESIDUE_POINTER
%FORMAT(10I8)
1
%FLAG BOND_FORCE_CONSTANT
%FORMAT(5E16.8)

%FLAG BOND_EQUIL_VALUE
%FORMAT(5E16.8)

%FLAG ANGLE_FORCE_CONSTANT
%FORMAT(5E16.8)

%FLAG ANGLE_EQUIL_VALUE
%FORMAT(5E16.8)

%FLAG DIHEDRAL_FORCE_CONSTANT
%FORMAT(5E16.8)

%FLAG DIHEDRAL_PERIODICITY
%FORMAT(5E16.8)

%FLAG DIHEDRAL_PHASE
%FORMAT(5E16.8)

%FLAG SCEE_SCALE_FACTOR
%FORMAT(5E16.8)

%FLAG SCNB_SCALE_FACTOR
%FORMAT(5E16.8)

%FLAG SOLTY
%FORMAT(5E16.8)
0.00000000E+00
%FLAG LENNARD_JONES_ACOEF
%FORMAT(5E16.8)
9.33304478E+06
%FLAG LENNARD_JONES_BCOEF
%FORMAT(5E16.8)
6.59809978E+02
%FLAG BONDS_INC_HYDROGEN
%FORMAT(10I8)

%FLAG BONDS_WITHOUT_HYDROGEN
%FORMAT(10I8)

%FLAG ANGLES_INC_HYDROGEN
%FORMAT(10I8)

%FLAG ANGLES_WITHOUT_HYDROGEN
%FORMAT(10I8)

%FLAG DIHEDRALS_INC_HYDROGEN
%FORMAT(10I8)

%FLAG DIHEDRALS_WITHOUT_HYDROGEN
%FORMAT(10I8)

%FLAG EXCLUDED_ATOMS_LIST
%FORMAT(10I8)
0
%FLAG HBOND_ACOEF
%FORMAT(5E16.8)

%FLAG HBOND_BCOEF
%FORMAT(5E16.8)

%FLAG HBCUT
%FORMAT(5E16.8)

%FLAG AMBER_ATOM_TYPE
%FORMAT(20a4)
Cl-
%FLAG TREE_CHAIN_CLASSIFICATION
%FORMAT(20a4)
M
%FLAG JOIN_ARRAY
%FORMAT(10I8)
0
%FLAG IROTAT
%FORMAT(10I8)
0
%FLAG RADIUS_SET
%FORMAT(1a80)
modified Bondi radii (mbondi)
%FLAG RADII
%FORMAT(5E16.8)
1.70000000E+00
%FLAG SCREEN
%FORMAT(5E16.8)
8.00000000E-01
%FLAG ATOMS_PER_MOLECULE
%FORMAT(10I8)
1
%FLAG IPOL
%FORMAT(1I8)
0
Loading

0 comments on commit 3c890c3

Please sign in to comment.