votca 2024.1-dev
Loading...
Searching...
No Matches
stdanalysis.cc
Go to the documentation of this file.
1/*
2 * Copyright 2009-2019 The VOTCA Development Team (http://www.votca.org)
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 */
17
18#include "stdanalysis.h"
19#include "analysistool.h"
20#include "bondedstatistics.h"
21#include <fstream>
22#include <iostream>
23#include <vector>
26
27namespace votca {
28namespace csg {
29
30void StdAnalysis::Register(std::map<std::string, AnalysisTool *> &lib) {
31 lib["list"] = this;
32 lib["vals"] = this;
33 lib["cor"] = this;
34 lib["autocor"] = this;
35}
36
37void StdAnalysis::Command(BondedStatistics &bs, const std::string &cmd,
38 std::vector<std::string> &args) {
39 if (cmd == "vals") {
40 WriteValues(bs, args);
41 }
42 if (cmd == "cor") {
43 WriteCorrelations(bs, args);
44 }
45 if (cmd == "autocor") {
46 WriteAutocorrelation(bs, args);
47 }
48 if (cmd == "list") {
50 bs.BondedValues().select("*");
51 std::cout << "Available bonded interactions:" << std::endl;
52 for (auto &array : *sel) {
53 std::cout << array->getName() << " " << std::endl;
54 }
55 delete sel;
56 }
57}
58
59void StdAnalysis::Help(const std::string &cmd, std::vector<std::string> &) {
60 if (cmd == "vals") {
61 std::cout
62 << "vals <file> <selection>\n"
63 << "write values to file. The first row is the frame number, then one "
64 << "row for each interaction specified. The output can be used to "
65 "generate "
66 << "2D correlation plots.\n\n"
67 << "example: vals angle *angle*\n";
68 }
69 if (cmd == "cor") {
70 std::cout
71 << "cor <file> <selection>\n"
72 << "Calculate linear correlation coefficient of the first item in "
73 "selection with all the other items\n"
74 << "WARNING: for evaluating correlations in the system, it is not "
75 "sufficient to calculate the "
76 << "linear correlation coefficient, 2D histograms with data from the "
77 "vals command should be used instead!\n";
78 }
79 if (cmd == "autocor") {
80 std::cout
81 << "autocor <file> <interaction>\n"
82 << "calculate autocorrelation function of first item in selection. "
83 "The output is periodic since FFTW3 is used to "
84 "calcualte correlations.\n";
85 }
86 if (cmd == "list") {
87 std::cout << "list\nlists all available interactions\n";
88 }
89}
90
92 std::vector<std::string> &args) {
93 std::ofstream out;
94
96
97 for (size_t i = 1; i < args.size(); i++) {
98 sel = bs.BondedValues().select(args[i], sel);
99 }
100
101 out.open(args[0]);
102 out << *sel << std::endl;
103 out.close();
104 std::cout << "written " << sel->size() << " data rows to " << args[0]
105 << std::endl;
106 delete sel;
107}
108
110 std::vector<std::string> &args) {
111 std::ofstream out;
113
114 for (size_t i = 1; i < args.size(); i++) {
115 sel = bs.BondedValues().select(args[i], sel);
116 }
117
119 c.AutoCorrelate(*sel);
120 out.open(args[0]);
121 out << c << std::endl;
122 out.close();
123 std::cout << "calculated autocorrelation for " << sel->size()
124 << " data rows, written to " << args[0] << std::endl;
125 delete sel;
126}
127
129 std::vector<std::string> &args) {
130 std::ofstream out;
132
133 for (size_t i = 1; i < args.size(); i++) {
134 sel = bs.BondedValues().select(args[i], sel);
135 }
136
138 c.CalcCorrelations(*sel);
139 out.open(args[0]);
140 out << c << std::endl;
141 out.close();
142 std::cout << "calculated correlations for " << sel->size()
143 << " rows, written to " << args[0] << std::endl;
144 delete sel;
145}
146
147} // namespace csg
148} // namespace votca
Class calculates data associated with bond interactions.
tools::DataCollection< double > & BondedValues()
void Help(const std::string &cmd, std::vector< std::string > &args) override
void Register(std::map< std::string, AnalysisTool * > &lib) override
void WriteCorrelations(BondedStatistics &bs, std::vector< std::string > &args)
void WriteValues(BondedStatistics &bs, std::vector< std::string > &args)
void Command(BondedStatistics &bs, const std::string &cmd, std::vector< std::string > &args) override
void WriteAutocorrelation(BondedStatistics &bs, std::vector< std::string > &args)
class to calculate correlations of values
Definition correlate.h:35
void CalcCorrelations(DataCollection< double >::selection &data)
Definition correlate.cc:24
class to calculate cross correlations and autocorrelations
void AutoCorrelate(DataCollection< double >::selection &data)
selection * select(std::string strselection, selection *sel_append=nullptr)
select a set of arrays
base class for all analysis tools
Definition basebead.h:33