2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2011,2012,2013,2014,2015, 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.
38 #include <gromacs/trajectoryanalysis.h>
39 #include <gromacs/math/do_fit.h>
40 #include <gromacs/utility/smalloc.h>
51 crcl return_crcl(long double x1, long double y1, long double z1,
52 long double x2, long double y2, long double z2,
53 long double x3, long double y3, long double z3) {
54 long double c, b, a, z, y, x, r;
55 long double a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12;
57 c = (z3 - z1 * x3 / x1 - (z2 - z1 * x2 / x1) / (y2 - y1 * x2 / x1)) / (1 - x3 / x1 - (1 - x2 / x1) / (y2 - y1 * x2 / x1));
58 //std::cout << c << " ";
59 //std::cout << y1 * (x2 / x1) << " ";
60 b = (y2 - y1 * x2 / x1) / (1 - x2 / x1 - 1 / c * (z2 - z1 * x2 / x1));
61 //std::cout << b << " ";
62 a = (x1) / (1 - y1 / b - z1 / c);
63 //std::cout << a << " ";
73 a8 = (x3 * x3 - x1 * x1) + (y3 * y3 - y1 * y1) + (z3 * z3 - z1 * z1);
78 a12 = (x3 * x3 - x2 * x2) + (y3 * y3 - y2 * y2) + (z3 * z3 - z2 * z2);
80 /*std::cout << a1 << " " << a2 << " " << a3 << " " << a4 << " "
81 << a5 << " " << a6 << " " << a7 << " " << a8 << " "
82 << a9 << " " << a10 << " " << a11 << " " << a12 << " ";*/
84 z = (a12 - a9 * a4 / a1 - (a10 - a9 * a2 / a1) * (a8 - a5 * a4 / a1) / (a6 - a5 * a2 / a1)) /
85 (a11 - a9 * a3 / a1 - (a10 - a9 * a2 / a1) * (a7 - a5 * a3 / a1) / (a6 - a5 * a2 / a1));
86 //std::cout << z << " ";
87 y = 1 / (a6 - a5 * a2 / a1) * (a8 - a5 * a4 / a1 - z * (a7 - a5 * a3 / a1));
88 //std::cout << y << " ";
89 x = 1 / a1 * (a4 - a2 * y - a3 * z);
90 //std::cout << x << " ";
91 r = std::sqrt((x - x3) * (x - x3) + (y - y3) * (y - y3) + (z - z3) * (z - z3));
92 //std::cout << r << " ";
105 * Template class to serve as a basis for user analysis tools.
107 class Spirals : public TrajectoryAnalysisModule
112 virtual void initOptions(IOptionsContainer *options,
113 TrajectoryAnalysisSettings *settings);
114 virtual void initAnalysis(const TrajectoryAnalysisSettings &settings,
115 const TopologyInformation &top);
117 virtual void analyzeFrame(int frnr, const t_trxframe &fr, t_pbc *pbc,
118 TrajectoryAnalysisModuleData *pdata);
120 virtual void finishAnalysis(int nframes);
121 virtual void writeOutput();
130 AnalysisNeighborhood nb_;
133 AnalysisDataAverageModulePointer avem_;
137 std::vector< std::vector < RVec > > trajectory;
138 std::vector< int > index;
145 registerAnalysisDataset(&data_, "avedist");
149 Spirals::initOptions(IOptionsContainer *options,
150 TrajectoryAnalysisSettings *settings)
152 static const char *const desc[] = {
153 "Analysis tool for finding molecular core."
156 // Add the descriptive text (program help text) to the options
157 settings->setHelpText(desc);
158 // Add option for selecting a subset of atoms
159 options->addOption(SelectionOption("select")
160 .store(&selec).required()
161 .description("Atoms that are considered as part of the excluded volume"));
162 // Add option for output file name
163 options->addOption(FileNameOption("on").filetype(eftIndex).outputFile()
164 .store(&fnNdx_).defaultBasename("rcore")
165 .description("Index file from the rcore"));
168 // -s '/home/toluk/Develop/samples/reca_rd/reca_rd.mono.tpr' -f '/home/toluk/Develop/samples/reca_rd/reca_rd.mono.xtc' -n '/home/toluk/Develop/samples/reca_rd/test.ndx' -on '/home/toluk/Develop/samples/reca_rd/core.ndx'
171 Spirals::initAnalysis(const TrajectoryAnalysisSettings &settings,
172 const TopologyInformation & /*top*/)
175 ConstArrayRef< int > atomind = selec.atomIndices();
176 for (ConstArrayRef< int >::iterator ai = atomind.begin(); (ai < atomind.end()); ai++)
178 index.push_back(*ai);
183 Spirals::analyzeFrame(int frnr, const t_trxframe &fr, t_pbc *pbc,
184 TrajectoryAnalysisModuleData *pdata)
186 trajectory.resize(frames + 1);
187 trajectory[frames].resize(index.size());
188 for (int i = 0; i < index.size(); i++)
190 trajectory[frames][i] = fr.x[index[i]];
196 Spirals::finishAnalysis(int /*nframes*/)
198 long double x1, y1, z1, x2, y2, z2, x3, y3, z3;
201 for (long double r = 1; r < 50; r++) {
202 for (long double x0 = -5; x0 < 6; x0+=0.99) {
203 for (long double y0 = -5; y0 < 6; y0+=0.99) {
210 y1 = std::sqrt(r * r - (x1 - x0) * (x1 - x0)) + y0;
211 y2 = std::sqrt(r * r - (x2 - x0) * (x2 - x0)) + y0;
212 y3 = std::sqrt(r * r - (x3 - x0) * (x3 - x0)) + y0;
214 /*std::cout << x1 << " " << y1 << " " << z1 << " "
215 << x2 << " " << y2 << " " << z2 << " "
216 << x3 << " " << y3 << " " << z3 << "\n";*/
218 test = return_crcl(x1, y1, z1, x2, y2, z2, x3, y3, z3);
220 //std::cout.precision(1);
221 //std::cout.width(3);
222 //std::cout << std::abs(x0 - test.x) << " " << std::abs(y0 - test.y) << " " << std::abs(1 - test.z) << " " << std::abs(r - test.r) << "\n";
227 for (int i = 0; i < 1; i++) {
228 for (int j = 0; j < index.size() - 2; j++) {
229 test = return_crcl( trajectory[i][j][0], trajectory[i][j][1], trajectory[i][j][2],
230 trajectory[i][j + 1][0], trajectory[i][j + 1][1], trajectory[i][j + 1][2],
231 trajectory[i][j + 2][0], trajectory[i][j + 2][1], trajectory[i][j + 2][2]);
232 std::cout << test.x << " " << test.y << " " << test.z << " " << test.r << "\n";
239 Spirals::writeOutput()
245 * The main function for the analysis template.
248 main(int argc, char *argv[])
250 return gmx::TrajectoryAnalysisCommandLineRunner::runAsMain<Spirals>(argc, argv);