2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2020, by the GROMACS development team, led by
5 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6 * and including many others, as listed in the AUTHORS file in the
7 * top-level source directory and at http://www.gromacs.org.
9 * GROMACS is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public License
11 * as published by the Free Software Foundation; either version 2.1
12 * of the License, or (at your option) any later version.
14 * GROMACS is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with GROMACS; if not, see
21 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 * If you want to redistribute modifications to GROMACS, please
25 * consider that scientific software is very special. Version
26 * control is crucial - bugs must be traceable. We will be happy to
27 * consider code for inclusion in the official distribution, but
28 * derived work must not be called official GROMACS. Details are found
29 * in the README & COPYING files - if they are missing, get the
30 * official version at http://www.gromacs.org.
32 * To help us fund GROMACS development, we humbly ask that you cite
33 * the research papers on the package. Check out http://www.gromacs.org.
35 /*! \inpublicapi \file
37 * Implements nblib Topology and TopologyBuilder
39 * \author Victor Holanda <victor.holanda@cscs.ch>
40 * \author Joe Jordan <ejjordan@kth.se>
41 * \author Prashanth Kanduri <kanduri@cscs.ch>
42 * \author Sebastian Keller <keller@cscs.ch>
43 * \author Artem Zhmurov <zhmurov@gmail.com>
45 #ifndef NBLIB_TOPOLOGY_H
46 #define NBLIB_TOPOLOGY_H
50 #include "nblib/interactions.h"
51 #include "nblib/molecules.h"
52 #include "nblib/topologyhelpers.h"
65 * \brief System Topology
67 * Contains all topology information meant to be used by the simulation
68 * engine internally. Private constructor ensures that a Topology object
69 * exists in a scope in a valid state after it has been built using a
76 //! Returns the total number of particles in the system
77 int numParticles() const;
79 //! Returns a vector of particle types
80 std::vector<ParticleType> getParticleTypes() const;
82 //! Return the ParticleType ID of all particles
83 std::vector<int> getParticleTypeIdOfAllParticles() const;
85 //! Returns a vector of particles partial charges
86 std::vector<real> getCharges() const;
88 //! Returns exclusions in proper, performant, GROMACS layout
89 gmx::ListOfLists<int> getGmxExclusions() const;
91 //! Returns the unique ID of a specific particle belonging to a molecule in the global space
92 int sequenceID(MoleculeName moleculeName, int moleculeNr, ResidueName residueName, ParticleName particleName) const;
94 //! Returns a map of non-bonded force parameters indexed by ParticleType names
95 NonBondedInteractionMap getNonBondedInteractionMap() const;
97 //! Returns the combination rule used to generate the NonBondedInteractionMap
98 CombinationRule getCombinationRule() const;
101 Topology() = default;
103 friend class TopologyBuilder;
105 //! Total number of particles in the system
107 //! unique collection of ParticleTypes
108 std::vector<ParticleType> particleTypes_;
109 //! store an ID of each particles's type
110 std::vector<int> particleTypeIdOfAllParticles_;
111 //! Storage for particles partial charges
112 std::vector<real> charges_;
113 //! Information about exclusions.
114 gmx::ListOfLists<int> exclusions_;
115 //! Associate molecule, residue and particle names with sequence numbers
116 detail::ParticleSequencer particleSequencer_;
117 //! Map that should hold all nonbonded interactions for all particle types
118 NonBondedInteractionMap nonBondedInteractionMap_;
119 //! Combination Rule used to generate the nonbonded interactions
120 CombinationRule combinationRule_;
123 /*! \brief Topology Builder
128 * A helper class to assist building of topologies. They also ensure that
129 * topologies only exist in a valid state within the scope of the
130 * simulation program.
133 class TopologyBuilder final
140 * Builds and Returns a valid Topology
142 * This function accounts for all the molecules added along with their
143 * exclusions and returns a topology with a valid state that is usable
144 * by the GROMACS back-end.
146 Topology buildTopology();
148 //! Adds a molecules of a certain type into the topology
149 TopologyBuilder& addMolecule(const Molecule& moleculeType, int nMolecules);
151 //! Add non-bonded interaction map to the topology
152 void addParticleTypesInteractions(const ParticleTypesInteractions& particleTypesInteractions);
155 //! Internally stored topology
158 //! Total number of particles in the system
161 //! List of molecule types and number of molecules
162 std::vector<std::tuple<Molecule, int>> molecules_;
164 //! Builds a GROMACS-compliant performant exclusions list aggregating exclusions from all molecules
165 gmx::ListOfLists<int> createExclusionsListOfLists() const;
167 //! Helper function to extract quantities like mass, charge, etc from the system
168 template<typename T, class Extractor>
169 std::vector<T> extractParticleTypeQuantity(Extractor&& extractor);
171 //! Distinct collection of ParticleTypes
172 std::unordered_map<std::string, ParticleType> particleTypes_;
174 //! ParticleType nonbonded parameters
175 ParticleTypesInteractions particleTypesInteractions_;
180 #endif // NBLIB_TOPOLOGY_H