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_;
138 std::vector< std::vector < RVec > > trajectory;
139 std::vector< std::vector< int > > index_all;
140 std::vector< int > index;
147 registerAnalysisDataset(&data_, "avedist");
151 Spirals::initOptions(IOptionsContainer *options,
152 TrajectoryAnalysisSettings *settings)
154 static const char *const desc[] = {
155 "Analysis tool for finding molecular core."
158 // Add the descriptive text (program help text) to the options
159 settings->setHelpText(desc);
160 // Add option for output file name
161 options->addOption(FileNameOption("on").filetype(eftIndex).outputFile()
162 .store(&fnNdx_).defaultBasename("rcore")
163 .description("Index file from the rcore"));
164 // Add option for selection list
165 options->addOption(SelectionOption("Select groups").storeVector(&sel_)
166 .required().dynamicMask().multiValue()
167 .description("Domains to form rigid skeleton"));
170 // -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'
173 Spirals::initAnalysis(const TrajectoryAnalysisSettings &settings,
174 const TopologyInformation & /*top*/)
176 std::vector< int > a;
180 for (int i = 0; i < sel_.size(); i++) {
181 index_all.push_back(a);
182 ConstArrayRef< int > atomind = sel_[i].atomIndices();
183 for (ConstArrayRef< int >::iterator ai = atomind.begin(); (ai < atomind.end()); ai++) {
184 index_all.back().push_back(*ai);
185 index.push_back(*ai);
191 Spirals::analyzeFrame(int frnr, const t_trxframe &fr, t_pbc *pbc,
192 TrajectoryAnalysisModuleData *pdata)
194 trajectory.resize(frames + 1);
195 trajectory[frames].resize(index.size());
196 for (int i = 0; i < index.size(); i++)
198 trajectory[frames][i] = fr.x[index[i]];
204 Spirals::finishAnalysis(int /*nframes*/)
206 long double x1, y1, z1, x2, y2, z2, x3, y3, z3;
209 for (long double r = 1; r < 50; r++) {
210 for (long double x0 = -5; x0 < 6; x0+=0.99) {
211 for (long double y0 = -5; y0 < 6; y0+=0.99) {
218 y1 = std::sqrt(r * r - (x1 - x0) * (x1 - x0)) + y0;
219 y2 = std::sqrt(r * r - (x2 - x0) * (x2 - x0)) + y0;
220 y3 = std::sqrt(r * r - (x3 - x0) * (x3 - x0)) + y0;
222 /*std::cout << x1 << " " << y1 << " " << z1 << " "
223 << x2 << " " << y2 << " " << z2 << " "
224 << x3 << " " << y3 << " " << z3 << "\n";*/
226 test = return_crcl(x1, y1, z1, x2, y2, z2, x3, y3, z3);
228 //std::cout.precision(1);
229 //std::cout.width(3);
230 //std::cout << std::abs(x0 - test.x) << " " << std::abs(y0 - test.y) << " " << std::abs(1 - test.z) << " " << std::abs(r - test.r) << "\n";
235 std::vector< std::vector< long double > > masses;
238 for (int i = 0; i < index_all.size(); i++) {
239 std::vector< long double > center;
241 for (int j = 0; j < index_all[i].size(); j++) {
242 center[0] += trajectory[0][count][0];
243 center[1] += trajectory[0][count][1];
244 center[2] += trajectory[0][count][2];
247 center[0] /= index_all[i].size();
248 center[1] /= index_all[i].size();
249 center[2] /= index_all[i].size();
250 masses.push_back(center);
254 for (int i = 0; i < 1; i++) {
255 for (int j = 0; j < masses.size() - 2; j++) {
256 /*test = return_crcl( trajectory[i][j][0], trajectory[i][j][1], trajectory[i][j][2],
257 trajectory[i][j + 1][0], trajectory[i][j + 1][1], trajectory[i][j + 1][2],
258 trajectory[i][j + 2][0], trajectory[i][j + 2][1], trajectory[i][j + 2][2]);*/
259 test = return_crcl( masses[j][0], masses[j][1], masses[j][2],
260 masses[j + 1][0], masses[j + 1][1], masses[j + 1][2],
261 masses[j + 2][0], masses[j + 2][1], masses[j + 2][2]);
262 std::cout << test.x << " " << test.y << " " << test.z << " " << test.r << "\n";
269 Spirals::writeOutput()
275 * The main function for the analysis template.
278 main(int argc, char *argv[])
280 return gmx::TrajectoryAnalysisCommandLineRunner::runAsMain<Spirals>(argc, argv);