GROMACS forcefields¶
Angle
dataclass
¶
Represents an angle formed by three atoms in a molecule.
This class models an angle, which is defined by three atoms, typically used to represent the geometric structure of a molecule. Angles are crucial in molecular dynamics simulations for defining the spatial arrangement of atoms and calculating potential energy based on geometric constraints.
Attributes:
Name | Type | Description |
---|---|---|
id_i |
int
|
The identifier of the first atom forming the angle. |
id_j |
int
|
The identifier of the second atom (vertex) forming the angle. |
id_k |
int
|
The identifier of the third atom forming the angle. |
funct |
int
|
The function type of the angle. In GROMACS, this typically refers to the type of angle potential used. |
angle |
float
|
The value of the angle, usually in degrees. |
force_constant |
float
|
The force constant of the angle, describing its stiffness. |
Class Methods
parse_from_itp_entry(cls, entry: list) -> "Angle": Parses angle information from a given entry in a topology file.
Source code in martignac/parsers/gromacs_forcefields.py
Atom
dataclass
¶
Represents an atom within a molecule.
This class models an atom's properties, including its unique identifier, type, residue information, and charge. It also provides a class method to parse atom information from a topology file entry.
Attributes:
Name | Type | Description |
---|---|---|
id |
int
|
Unique identifier of the atom within the molecule. |
type |
str
|
Type of the atom, defining its chemical characteristics. |
residue_number |
int
|
Identifier of the residue the atom belongs to. |
residue |
str
|
Name of the residue the atom belongs to. |
atom |
str
|
Name of the atom. |
charge_number |
int
|
Identifier for the charge group the atom belongs to. |
charge |
int
|
The charge of the atom. |
Class Methods
parse_from_itp_entry(cls, entry: list) -> "Atom": Parses atom information from a given topology file entry and returns an Atom instance.
Source code in martignac/parsers/gromacs_forcefields.py
Bond
dataclass
¶
Bases: Constraint
Represents a bond between two atoms in a molecule, extending the Constraint class.
This class models a bond as a specialized type of constraint with an additional attribute for the force constant. Bonds are used to define the fixed distance between two atoms along with the force constant that describes the strength of the bond. This is particularly useful in molecular dynamics simulations for defining the interactions and energy calculations between atoms.
Attributes:
Name | Type | Description |
---|---|---|
id_i |
int
|
The identifier of the first atom in the bond. |
id_j |
int
|
The identifier of the second atom in the bond. |
funct |
int
|
The function type of the bond. In GROMACS, this typically refers to the type of bond algorithm used. |
length |
float
|
The length of the bond, usually in nanometers. |
force_constant |
float
|
The force constant of the bond, describing its strength. |
Class Methods
parse_from_itp_entry(cls, entry: list) -> "Bond": Parses a bond from a given entry in a topology file, extending the Constraint class method with an additional parameter for the force constant.
Source code in martignac/parsers/gromacs_forcefields.py
Constraint
dataclass
¶
Represents a constraint between two atoms in a molecule.
This class models a constraint, which is a fixed distance between two atoms, typically used to maintain a certain structure within the molecule. Constraints are often used in molecular dynamics simulations to simplify the model or enforce certain conditions.
Attributes:
Name | Type | Description |
---|---|---|
id_i |
int
|
The identifier of the first atom in the constraint. |
id_j |
int
|
The identifier of the second atom in the constraint. |
funct |
int
|
The function type of the constraint. In GROMACS, this typically refers to the type of constraint algorithm used. |
length |
float
|
The length of the constraint, usually in nanometers. |
Class Methods
parse_from_itp_entry(cls, entry: list) -> "Constraint": Parses a constraint from a given entry in a topology file.
Source code in martignac/parsers/gromacs_forcefields.py
Molecule
dataclass
¶
Represents a molecule with its constituent atoms, bonds, angles, and constraints.
This class encapsulates a molecule's structure, including its atoms and the relationships between them (bonds, angles, and constraints). It provides methods for generating molecular coordinates, parsing molecule data from topology files, and generating files for molecular dynamics simulations.
Attributes:
Name | Type | Description |
---|---|---|
name |
str
|
The name of the molecule. |
number_excl |
int
|
The number of exclusions for the molecule, used in simulations to define non-bonded interactions. |
atoms |
list[Atom]
|
A list of |
bonds |
Optional[list[Bond]]
|
A list of |
angles |
Optional[list[Angle]]
|
A list of |
constraints |
Optional[list[Constraint]]
|
A list of |
Methods:
Name | Description |
---|---|
num_atoms |
Returns the number of atoms in the molecule. |
generate_coordinates |
float = 0.1) -> np.ndarray: Generates 3D coordinates for the atoms in the molecule. |
parse_from_itp_entry |
dict) -> "Molecule": Class method to parse a molecule from a topology file entry. |
Source code in martignac/parsers/gromacs_forcefields.py
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 |
|
find_molecule_from_name(itp_filenames, molecule_name)
¶
Searches for and returns a Molecule instance matching the specified name from a list of .itp files.
This function iterates over a list of GROMACS topology (.itp) files, parsing each to find a molecule
that matches the given name. It leverages the parse_molecules_from_itp
function to parse the .itp files
and then searches through the resulting list of Molecule instances for a name match. The first matching
Molecule instance found is returned. If no match is found after all files have been searched, a StopIteration
exception is raised.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
itp_filenames |
list[str]
|
A list of paths to .itp files to be searched. |
required |
molecule_name |
str
|
The name of the molecule to find. |
required |
Returns:
Name | Type | Description |
---|---|---|
Molecule |
Molecule
|
The first Molecule instance found with a name matching |
Raises:
Type | Description |
---|---|
StopIteration
|
If no molecule with the specified name is found in the provided .itp files. |
Source code in martignac/parsers/gromacs_forcefields.py
generate_gro_file_for_molecule(molecule, gro_filename, box_length=100.0)
¶
Generates a GROMACS .gro file for a given molecule.
This function creates a .gro file, which is a GROMACS file format used to describe the positions of atoms in a molecule.
It sets up a simulation box with a specified box length and places the atoms of the molecule within this box. The positions
of the atoms are determined by the generate_coordinates
method of the Molecule
class, and additional molecular properties
such as bonds are also considered if present.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
molecule |
Molecule
|
The molecule for which to generate the .gro file. |
required |
gro_filename |
str
|
The path and name of the .gro file to be generated. |
required |
box_length |
float
|
The length of the sides of the cubic simulation box in which the molecule is placed. Default is 100.0. |
100.0
|
Returns:
Name | Type | Description |
---|---|---|
None |
None
|
This function does not return a value but writes directly to a file. |
Source code in martignac/parsers/gromacs_forcefields.py
369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 |
|
generate_itp_file_for_molecule(molecule, itp_filename)
¶
Generates a GROMACS topology (.itp) file for a specified molecule.
This function writes a .itp file containing the definition of a molecule, including atoms, bonds, angles, and constraints. The file format adheres to the GROMACS topology file standards, making it suitable for use in molecular dynamics simulations. The function outputs sections for moleculetype, atoms, bonds (if any), angles (if any), and constraints (if any), providing a comprehensive description of the molecule's structure.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
molecule |
Molecule
|
The molecule instance for which to generate the .itp file. This object should contain all necessary information about the molecule, including its atoms, bonds, angles, and constraints. |
required |
itp_filename |
str
|
The path and name of the .itp file to be generated. If the file already exists, it will be overwritten. |
required |
Returns:
Name | Type | Description |
---|---|---|
None |
None
|
This function does not return a value but writes directly to a file specified by |
Source code in martignac/parsers/gromacs_forcefields.py
generate_top_file_for_molecule(molecule, force_field_filenames, top_filename, num_molecules=1)
¶
Generates a GROMACS topology (.top) file for a given molecule using specified force fields.
This function delegates the task of generating a .top file to the generate_top_file_for_generic_molecule
utility function. It prepares the necessary parameters, including the molecule's name, the list of force field
filenames, the target .top file name, and the number of molecules to be included in the simulation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
molecule |
Molecule
|
The molecule instance for which to generate the .top file. |
required |
force_field_filenames |
list[str]
|
A list of strings representing the paths to the force field files to be used. |
required |
top_filename |
str
|
The path and name of the .top file to be generated. |
required |
num_molecules |
int
|
The number of molecules to be included in the .top file. Default is 1. |
1
|
Returns:
Name | Type | Description |
---|---|---|
None |
None
|
This function does not return a value but writes directly to a file. |
Source code in martignac/parsers/gromacs_forcefields.py
get_molecule_from_name(molecule_name, bond_length, bond_constant=None, number_excl=3, molecule_label=None)
¶
Constructs a Molecule instance from a simplified molecule name string.
This function allows for the creation of a Molecule object by specifying a string that represents the molecule's composition, bond lengths, and optionally, bond constants. It supports the definition of atoms, bonds, and constraints within the molecule based on the provided string format. The molecule name string format should include atom types, followed by bond information (if any), separated by commas.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
molecule_name |
str
|
A string representing the molecule's composition and structure. Atom types should be separated by spaces, and bond information (if any) should follow after a comma. Bonds are indicated by indices of atoms (starting from 1) connected by a dash ("-") for bonds or an underscore ("_") for constraints. |
required |
bond_length |
float
|
The default length for bonds and constraints within the molecule, in nanometers. |
required |
bond_constant |
Optional[float]
|
The force constant for the bonds within the molecule. This parameter is required if the molecule_name string includes bond information. Default is None. |
None
|
number_excl |
int
|
The number of exclusions for the molecule, used in simulations to define non-bonded interactions. Default is 3. |
3
|
molecule_label |
Optional[str]
|
An optional label for the molecule. If not provided, a label is generated from the first five characters of the concatenated atom types. Default is None. |
None
|
Returns:
Name | Type | Description |
---|---|---|
Molecule |
Molecule
|
An instance of the Molecule class, constructed based on the provided parameters. |
Raises:
Type | Description |
---|---|
ValueError
|
If bond_constant is None but the molecule_name string includes bond information. |
Source code in martignac/parsers/gromacs_forcefields.py
parse_molecules_from_itp(itp_filename)
¶
Parses molecules from a GROMACS topology (.itp) file.
This function reads a .itp file, extracts molecule information, and creates a list of Molecule instances based on the data found in the file. It handles multiple molecules within the same file, separating them based on the [moleculetype] directive in the .itp file format. Each molecule's data is parsed and used to instantiate a Molecule object, which is then added to the list of molecules to be returned.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
itp_filename |
str
|
The path to the .itp file to be parsed. |
required |
Returns:
Type | Description |
---|---|
list[Molecule]
|
list[Molecule]: A list of Molecule instances representing each molecule found in the .itp file. |