Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
6635e81
DRR - Cpptraj: Move integration routines from DataSet_Mesh to DataSet_1D
Sep 12, 2019
1ee5fd3
DRR - Cpptraj: Use forward declare.
Sep 12, 2019
ee780c2
DRR - Cpptraj: Add some finite difference calcs
Sep 12, 2019
8de29a1
DRR - Cpptraj: Add functions to header
Sep 12, 2019
9245e16
DRR - Cpptraj: Warn when incoming X mesh doesnt have the right size
Sep 12, 2019
b0b686b
DRR - Cpptraj: Forward declare mesh
Sep 12, 2019
da10906
DRR - Cpptraj: Finite difference analysis class
Sep 12, 2019
01e756b
DRR - Cpptraj: Add slope command. Have finite difference routines set…
Sep 12, 2019
d4393b1
DRR - Cpptraj: Add finite difference test
Sep 12, 2019
035ca5c
DRR - Cpptraj: Have integrate routine with cumulative sum set X values.
Sep 12, 2019
36101f5
DRR - Cpptraj: Slight reorganization of loop for clarity
Sep 12, 2019
fa6134f
DRR - Cpptraj: Save final integral values to a data set; add 'intout'…
Sep 12, 2019
ecfe319
DRR - Cpptraj: Compare final integral value.
Sep 12, 2019
7cbf4a2
DRR - Cpptraj: Forgot to actually put the test in.
Sep 12, 2019
daa1506
DRR - Cpptraj: Better output.
Sep 12, 2019
8e582e1
DRR - Cpptraj: Revision bump for new slope (finite difference) analys…
Sep 12, 2019
a4fe6a6
DRR - Cpptraj: Enable slope test
Sep 12, 2019
23be767
DRR - Cpptraj: Simplify help
Sep 12, 2019
afdfd8e
DRR - Cpptraj: Update manual for new slope command and new integrate …
Sep 12, 2019
78a5ea7
Merge branch 'master' into addslope
Sep 12, 2019
ba4034a
DRR - Cpptraj: Remove sources to try to fix travis builds. Try to add…
Sep 12, 2019
62a9ba7
DRR - Cpptraj: Need to have the ubuntu-toolchain ppa in there.
Sep 12, 2019
2d58723
DRR - Cpptraj: Turns out pnetcdf not part of the toolchain
Sep 12, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@ language: cpp
dist: trusty
sudo: false
addons:
sources:
- ubuntu-toolchain-r-test
apt:
sources:
- ubuntu-toolchain-r-test
- george-edison55-precise-backports
packages:
- gfortran
- libbz2-dev
- libblas-dev
- liblapack-dev
- libarpack2-dev
- libnetcdf-dev
- libfftw3-dev
- netcdf-bin
Expand Down
Binary file modified doc/CpptrajManual.pdf
Binary file not shown.
136 changes: 134 additions & 2 deletions doc/cpptraj.lyx
Original file line number Diff line number Diff line change
Expand Up @@ -38804,11 +38804,79 @@ integrate
\end_layout

\begin_layout LyX-Code
integrate <dset0> [<dset1> ...] [out <outfile>] [name <outsetname>]
integrate <dset0> [<dset1> ...] [out <outfile>] [intout <intfile>]
\end_layout

\begin_layout LyX-Code
[name <name>]
\end_layout

\begin_deeper
\begin_layout Description
<dset0>
\begin_inset space ~
\end_inset

[<dset1>
\begin_inset space ~
\end_inset

...] Data set(s) to integrate.
\end_layout

\begin_layout Description
[out
\begin_inset space ~
\end_inset

<outfile>] If specified, write cumulative sum curves to <outfile>.
\end_layout

\begin_layout Description
[intout
\begin_inset space ~
\end_inset

<intfile>] If specified, write final integral values to <intfile>.
\end_layout

\begin_layout Description
[name
\begin_inset space ~
\end_inset

<name>] Output data set(s) name.
\end_layout

\begin_layout Standard
DataSets Created:
\end_layout

\begin_layout Description
<name> Final integral values, 1 for each input data set (indexed from 0).
\end_layout

\begin_layout Description
<name>[Sum]:<idx> Cumulative sum curves if
\series bold
out
\series default
was specified, 1 for each input data set (indexed from 0).
\end_layout

\end_deeper
\begin_layout Standard
Integrate specified data set(s) using trapezoid integration.
If
\series bold
'out'
\series default
is specified write cumulative sum curves to <outfile>.
If
\series bold
'intout'
\series default
is specified write final integral values for each set to <intfile>.
\end_layout

\begin_layout Subsection
Expand Down Expand Up @@ -42251,6 +42319,70 @@ Calculate running average over windows of given size for data in selected
data set(s).
\end_layout

\begin_layout Subsection
slope
\end_layout

\begin_layout LyX-Code
slope <dset0> [<dset1> ...] [out <outfile>] [name <name>]
\end_layout

\begin_layout LyX-Code
[type {forward|backward|central}]
\end_layout

\begin_deeper
\begin_layout Description
<dset0>
\begin_inset space ~
\end_inset

[<dset1>
\begin_inset space ~
\end_inset

...] Data set(s) to calculate finite difference for.
\end_layout

\begin_layout Description
[out
\begin_inset space ~
\end_inset

<outfile>] File to write finite difference curves to.
\end_layout

\begin_layout Description
[name
\begin_inset space ~
\end_inset

<name>] Output data set(s) name.
\end_layout

\begin_layout Description
[type
\begin_inset space ~
\end_inset

{forward|backward|central}] Specify type of finite difference to calculate
(default forward).
\end_layout

\begin_layout Standard
DataSets generated:
\end_layout

\begin_layout Description
<name>:<idx> Output finite difference curves for each input data set (indexed
from 0).
\end_layout

\end_deeper
\begin_layout Standard
Calculate finite differences for each input data set.
\end_layout

\begin_layout Subsection
spline
\end_layout
Expand Down Expand Up @@ -42310,7 +42442,7 @@ spline <dset0> [<dset1> ...] [out <outfile>] [meshsize <n> | meshfactor <x>]

\end_deeper
\begin_layout Standard
Cubic spline the given data sets.
Apply cubic splines to the given input data sets to create new data sets.
\end_layout

\begin_layout Subsection
Expand Down
5 changes: 1 addition & 4 deletions src/Action_VelocityAutoCorr.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "Action_VelocityAutoCorr.h"
#include "CpptrajStdio.h"
#include "ProgressBar.h"
#include "DataSet_Mesh.h"
#include "DataSet_double.h"
#include "Constants.h"
#include "Corr.h"
Expand Down Expand Up @@ -281,9 +280,7 @@ void Action_VelocityAutoCorr::Print() {
// Integration to get diffusion coefficient.
VAC_->SetDim(Dimension::X, Dimension(0.0, tstep_, "Time (ps)"));
mprintf("\tIntegrating data set %s, step is %f\n", VAC_->legend(), VAC_->Dim(0).Step());
DataSet_Mesh mesh;
mesh.SetMeshXY( static_cast<DataSet_1D const&>(*VAC_) );
double total = mesh.Integrate_Trapezoid();
double total = Ct.Integrate( DataSet_1D::TRAPEZOID );
const double ANG2_PS_TO_CM2_S = 10.0; // Convert Ang^2/ps to 1E-5 cm^2/s
const char* tab = "\t";
if (!diffout_->IsStream()) {
Expand Down
68 changes: 40 additions & 28 deletions src/Analysis_Integrate.cpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
#include "Analysis_Integrate.h"
#include "CpptrajStdio.h"
#include "DataSet_Mesh.h"

Analysis_Integrate::Analysis_Integrate() : outfile_(0) {}
Analysis_Integrate::Analysis_Integrate() : sumSet_(0) {}

void Analysis_Integrate::Help() const {
mprintf("\t<dset0> [<dset1> ...] [out <outfile>] [name <outsetname>]\n"
" Integrate given data sets.\n");
mprintf("\t<dset0> [<dset1> ...] [out <outfile>] [intout <intfile>]\n"
"\t[name <name>]\n"
" Integrate given data sets. If 'out' is specified write cumulative\n"
" sum curves to <outfile>. If 'intout' is specified write final\n"
" integral values for each set to <intfile>.\n");
}

Analysis::RetType Analysis_Integrate::Setup(ArgList& analyzeArgs, AnalysisSetup& setup, int debugIn)
{
std::string setname = analyzeArgs.GetStringKey("name");
outfile_ = setup.DFL().AddDataFile(analyzeArgs.GetStringKey("out"), analyzeArgs);
DataFile* outfile = setup.DFL().AddDataFile(analyzeArgs.GetStringKey("out"), analyzeArgs);
DataFile* intfile = setup.DFL().AddDataFile(analyzeArgs.GetStringKey("intout"), analyzeArgs);
// Select datasets from remaining args
if (input_dsets_.AddSetsFromArgs( analyzeArgs.RemainingArgs(), setup.DSL() )) {
mprinterr("Error: Could not add data sets.\n");
Expand All @@ -23,48 +28,55 @@ Analysis::RetType Analysis_Integrate::Setup(ArgList& analyzeArgs, AnalysisSetup&
}

// Set up output datasets
if (outfile_ != 0) {
if (setname.empty())
setname = setup.DSL().GenerateDefaultName("Int");
sumSet_ = setup.DSL().AddSet(DataSet::DOUBLE, setname);
if (sumSet_ == 0) return Analysis::ERR;
if (intfile != 0) intfile->AddDataSet( sumSet_ );
if (outfile != 0) {
int idx = 0;
MetaData md(setname, "Sum");
for (Array1D::const_iterator dsIn = input_dsets_.begin();
dsIn != input_dsets_.end(); ++dsIn)
{
DataSet* ds = setup.DSL().AddSet(DataSet::XYMESH, setname, "Int");
md.SetIdx(idx++);
DataSet* ds = setup.DSL().AddSet(DataSet::XYMESH, md);
if (ds == 0) return Analysis::ERR;
ds->SetLegend( "Int(" + (*dsIn)->Meta().Legend() + ")" );
outfile_->AddDataSet( ds );
outfile->AddDataSet( ds );
output_dsets_.push_back( (DataSet_Mesh*)ds );
}
}

mprintf(" INTEGRATE: Calculating integral of %zu data sets.\n",
mprintf(" INTEGRATE: Calculating integral for %zu data sets.\n",
input_dsets_.size());
if (outfile_ != 0) {
if (outfile != 0) {
if (!setname.empty())
mprintf("\tOutput set name: %s\n", setname.c_str());
mprintf("\tOutfile name: %s\n", outfile_->DataFilename().base());
mprintf("\tOutfile name: %s\n", outfile->DataFilename().base());
}
if (debugIn > 0) {
for (Array1D::const_iterator set = input_dsets_.begin(); set != input_dsets_.end(); ++set)
mprintf("\t%s\n", (*set)->legend());
}
//for (Array1D::const_iterator set = input_dsets_.begin(); set != input_dsets_.end(); ++set)
// mprintf("\t%s\n", (*set)->legend());
return Analysis::OK;
}

Analysis::RetType Analysis_Integrate::Analyze() {
double sum;
int idx = 0;
for (Array1D::const_iterator DS = input_dsets_.begin();
DS != input_dsets_.end(); ++DS, ++idx)
{
if ( (*DS)->Size() < 1)
mprintf("Warning: Set [%i] \"%s\" has no data.\n", idx, (*DS)->legend());
else {
DataSet_Mesh mesh;
// Set XY mesh
mesh.SetMeshXY( *(*DS) );
if (outfile_ != 0)
sum = mesh.Integrate_Trapezoid( *(output_dsets_[idx]) );
else
sum = mesh.Integrate_Trapezoid();
mprintf("\tIntegral of %s is %g\n", (*DS)->legend(), sum);
output_dsets_[idx]->SetDim(Dimension::X, (*DS)->Dim(0));
for (unsigned int idx = 0; idx != input_dsets_.size(); idx++) {
DataSet_1D const& inSet = *(input_dsets_[idx]);
if (inSet.Size() < 1) {
mprintf("Warning: Set '%s' has no data.\n", inSet.legend());
} else {
if (!output_dsets_.empty()) {
DataSet_Mesh& outSet = static_cast<DataSet_Mesh&>( *(output_dsets_[idx]) );
sum = inSet.Integrate( DataSet_1D::TRAPEZOID, outSet.SetMeshX(), outSet.SetMeshY() );
outSet.SetDim(Dimension::X, inSet.Dim(0));
} else
sum = inSet.Integrate( DataSet_1D::TRAPEZOID );
mprintf("\tIntegral of %s is %g\n", inSet.legend(), sum);
sumSet_->Add(idx, &sum);
}
}
return Analysis::OK;
Expand Down
4 changes: 2 additions & 2 deletions src/Analysis_Integrate.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define INC_ANALYSIS_INTEGRATE_H
#include "Analysis.h"
#include "Array1D.h"
#include "DataSet_Mesh.h"
class DataSet_Mesh;
class Analysis_Integrate : public Analysis {
public:
Analysis_Integrate();
Expand All @@ -12,8 +12,8 @@ class Analysis_Integrate : public Analysis {
Analysis::RetType Setup(ArgList&, AnalysisSetup&, int);
Analysis::RetType Analyze();
private:
DataFile* outfile_; // FIXME: May not need to be class var
Array1D input_dsets_;
std::vector<DataSet_Mesh*> output_dsets_;
DataSet* sumSet_; ///< Hold final sum for each set
};
#endif
2 changes: 1 addition & 1 deletion src/Analysis_Rotdif.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1590,7 +1590,7 @@ int Analysis_Rotdif::DetermineDeffs() {
// Calculate mesh Y values
spline.SetSplinedMeshY(pX, pY);
// Integrate
double integral = spline.Integrate_Trapezoid();
double integral = spline.Integrate( DataSet_1D::TRAPEZOID );
//mprintf("DEBUG: Vec %i integral= %g\n", nvec, integral);
// Solve for deff
D_eff_.push_back( calcEffectiveDiffusionConst(integral) );
Expand Down
Loading