Skip to content

Commit

Permalink
Major improvements to loops, misc other fixes (#789)
Browse files Browse the repository at this point in the history
* DRR - Use forward declares.

* DRR - Split ControlBlock class stuff from the Control file.

* DRR - Add missing file.

* DRR - Start trying to split out the various for loop types.

* DRR - Add mask for loop type

* DRR - Most of VarType only needed for mask type loop

* DRR - Have SetVarName prepend the $ automatically

* DRR - Add list for loop type

* DRR - Add begin and end functions.

* DRR - Add ForLoop files, update depends

* DRR - Try to use new ForLoop class. Doesnt appear to work yet...

* DRR - Need to account for prepended $

* DRR - Fix variable name and 'in' for list for loop

* DRR - Add GetVariable function

* DRR - Have loop start use CurrentVars

* DRR - Have BeginFor return the number of iterations.

* DRR - Number of iterations is now determined when loop starts.

* DRR - Allow end argument to be a variable. More informative messages on how many iterations loop will execute.

* DRR - Hide debug and change warning to info

* DRR - Hide some debug info

* DRR - Add MemUsageInBytes to template

* DRR - Add StringVar data set

* DRR - Add STRINGVAR to DataSet

* DRR - Add Add and append functions

* DRR - Add Exec version of the Set command

* DRR - Exec version of show command

* DRR - Start massive changes to move VariableArray functionality to DataSetList

* DRR - More work replacing VariableArray with DataSetList. Add some functions to DataSetList

* DRR - Add another check

* DRR - Add UpdateStringVar routine and make ForLoop_integer use it.

* DRR - Use DataSetList in remaining for loops.

* DRR - DSL can be const& for CheckDone

* DRR - Add list string variables function

* DRR - Finish up show exec. Still not quite working.

* DRR - Add comment

* DRR - Ensure loop variable is set up as a dataset

* DRR - Loop variable cannot be the same as DataSet name anymore

* DRR - Give vectors a name

* DRR - Give RMS sets a name

* DRR - Give distance sets a name

* DRR - Name sets

* DRR - Name sets

* DRR - Ensure final value of integer loops is updated to make behavior consistent with all common integer for loops

* DRR - Make 0 iteration loops a warning instead of an error. Ensure all integer for loops are properly integrated on loop end. Add >= and <= end ops.

* DRR - Make start and end values that will result in no iterations a warning, not an error

* DRR - No such thing as CTL objects anymore

* DRR - Fix help.

* DRR - More fixing up of help

* DRR - Add a check that for loop variable was properly set up. Hide some debug info

* DRR - Hide some more debug info

* DRR - Start adding data set blocks loop

* DRR - Exit if error occurrs setting up loop var

* DRR - More loop setup

* DRR - Make blocksize an unsigned int

* DRR - Start splitting for loop components into separate argument lists

* DRR - Better way of handling individual for loop components; should be no cross-contamination between multiple for loop components of the same type

* DRR - Change index vars to long int; refactor so that data set does not need to exist until loop is actually executed.

* DRR - Add missing file

* DRR - Finish initial loop - still need to actually create the sets

* DRR - Add test of nested loop vars and <= loop operator

* DRR - Enabled dataSetBlocks for loop

* DRR - DataSetList needs to be passed in non-const so that data sets can be created each iteration

* DRR - New class for abstracting data set copies

* DRR - Improve error message when no valid file type can be found for a given data set

* DRR - Use DataSetBlock

* DRR - No need to abstract to DataBlock, just require that DataSet of same type be used in function (now called CopyBlock); this will make it easier to make universal.

* DRR - Add MemAlloc and CopyBlock for mesh

* DRR - Fix up dependencies

* DRR - Start attempt to split DataSet_Vector into two sets, 1 with origins and 1 without

* DRR - Fix up Sync routines, update dependencies

* DRR - Fix shadowed variables

* DRR - Accidentally duplicated a function

* DRR - Add new vector types and group

* DRR - Enable new types in the DataSetList

* DRR - Ensure MemAlloc routine is declared

* DRR - Start converting to use new types

* DRR - More updates for new vector types

* DRR - prototype test for loop over datasetblocks

* DRR - More changes for new set types

* DRR - Finish fixing up vector action

* DRR - More VECTOR_1D changes

* DRR - More updates for new vector types

* DRR - Finish up vector changes. Still needs testing.

* DRR - Origin is no longer stored when not needed

* DRR - Vector origin no longer included when not needed

* DRR - Handle append of vector data sets inside DataIO_Std to handle case where data being read in type does not match existing set type

* DRR - Add reverse append test

* DRR - Ensure old memory is freed

* DRR - Add MemAlloc and CopyBlock for vector sets

* DRR - Add CopyBlock and MemAlloc routines to float and integer data sets

* DRR - Add initial test for data set blocks loop

* DRR - Improve error message

* DRR - Minor version bump; vector output for vectors with no origin data is different.

* DRR - Add a cumulative mode for datasetblocks

* DRR - Hide some debug info. Use CheckForSet to avoid spurious warnings.

* DRR - Add 'firstblock' keyword to cumulative datasetblocks to set size of first block

* DRR - Fix calculation of number of iterations.

* DRR - Allow 'show' to only show specified string vars

* DRR - If variables are replaced in a command, re-parse the Argument list in case new spaces have been introduced etc. May want to eventually have the ExecuteCommand function just take a string.

* DRR - Add test for cumulative blocks

* DRR - Hide some debug info

* DRR - Improve output message

* DRR - Allow multiple variables to be passed to show

* DRR - Fix loop descriptions

* DRR - Dont write unneeded temp files during test

* DRR - Fix manual entries

* DRR - Start adding advanced help for for loops

* DRR - Fix up for loop help

* DRR - Fix up for loop help in manual.

* DRR - Remove extra whitespace

* DRR - Give created datasetblocks sets an aspect to reduce the chances of collision. Set legend to be more descriptive.

* DRR - Updated set legends.

* DRR - Data set index +1 to be consistent with set legend

* DRR - Fix up for loop manual entry

* DRR - First check if string variable with name exists. This allows string variables to be used in data set name expressions, e.g. $i[phi]

* DRR - Implement data set copying for sets that support CopyBlock - otherwise revert to old behavior of renaming.

* DRR - Add data set copy test

* DRR - Minor version bump, vector output is different.

* DRR - Improve math help and manual entry

* DRR - Use forward declares. When processing expression, first remove all whitespace to make parsing easier.

* DRR - expression has already had all whitespace removed

* DRR - Add array that can be used to ID functions.

* DRR - Add function to identify functions in expression

* DRR - Use new function to look for function names. Should address #744

* DRR - Add test with function names

* DRR - More forward declares.

* DRR - More forward declares

* DRR - Add missing header guard

* DRR - Protect datasetblocks in parallel

* DRR - Allow wildcard expansion in 'for in' loop to fail with a warning.

* DRR - Add for loop over data sets.

* DRR - Enable oversets loop

* DRR - Test loop filename wildcards and oversets loop

* DRR - Add for oversets manual entry

* DRR - Add missing argument to printf.

* DRR - Add missing include.

* DRR - Make it so that list for loops can access script variables.

* DRR - Allow oversets loop to access script variables.

* DRR - Enable label print for grace xydy. Update help.

* DRR - Update manual

* DRR - I give up for now. Reverting DataSet_Vector changes so that pytraj will build and pass tests. I want the rest of the stuff committed before the amber meeting.

* DRR - Revert to DataSet_Vector

* DRR - Add MemAlloc and CopyBlock

* DRR - Reorganize routine order to separate vector and vector with origin functions. Cleanup.

* DRR - Revert to DataSet_Vector

* DRR - Cpptraj: Revert to DataSet_Vector

* DRR - Revert to DataSet_Vector

* DRR - Revert to DataSet_Vector

* DRR - Revert to DataSet_Vector

* DRR - Revert to DataSet_Vector

* DRR - Revert to DataSet_Vector.....

* DRR - Add missing include due to new forward declare

* DRR - Add missing include due to forward declare

* DRR - Revert to DataSet_Vector

* DRR - Revert to DataSet_Vector

* DRR - Make sure vector set is in VECTOR_1D group

* DRR - Revert to DataSet_Vector

* DRR - Revert to DataSet_Vector

* DRR - Update dependencies

* DRR - Add missing ref operator

* DRR - Revert tests, origins still printed for non-origin vector sets

* DRR - Decrement minor version; revision bump insteead, vector output now unchanged.
  • Loading branch information
drroe authored Jan 31, 2020
1 parent b836078 commit 12a3360
Show file tree
Hide file tree
Showing 120 changed files with 3,497 additions and 1,234 deletions.
1 change: 1 addition & 0 deletions devtools/Template.sh
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,7 @@ elif [ "$TYPE" = 'DataSet' ] ; then
void Add(size_t, const void*) { return; }
void WriteBuffer(CpptrajFile&, SizeArray const&) const { return; }
int Append(DataSet*) { return 1; }
size_t MemUsageInBytes() const { return 0; }
# ifdef MPI
int Sync(size_t, std::vector<int> const&, Parallel::Comm const&) { return 1; }
# endif
Expand Down
182 changes: 155 additions & 27 deletions doc/cpptraj.lyx
Original file line number Diff line number Diff line change
Expand Up @@ -1924,11 +1924,25 @@ script
variables and 'for' loops.
Script variables are referred to by a dollar sign ('$') prefix and are
replaced when they are processed.
Note that to use script variables in CPPTRAJ input that is also inside
e.g.
a BASH script, they can be escaped with the '
These are stored in the master data set list like other data and are assigned
the type
\begin_inset Quotes eld
\end_inset

string variable
\begin_inset Quotes erd
\end_inset

.

\series bold
Note that to use script variables in CPPTRAJ input that is inside another
script (e.g.
a BASH script), they must be escaped with the '
\backslash
' character, e.g.
' character,
\series default
e.g.
\end_layout

\begin_layout LyX-Code
Expand All @@ -1944,13 +1958,13 @@ cpptraj <<EOF
\end_layout

\begin_layout LyX-Code
set topname=$TOP
set topname=$TOP # TOP is a BASH script variable
\end_layout

\begin_layout LyX-Code
parm
\backslash
$topname
$topname # topname is a CPPTRAJ script variable
\end_layout

\begin_layout LyX-Code
Expand Down Expand Up @@ -2069,14 +2083,25 @@ for { {atoms|residues|molecules|molfirstres|mollastres}
\end_layout

\begin_layout LyX-Code
<var> inmask <mask> [parm <name> | parmindex <#> | <#>] ...
|
<var> inmask <mask> [parm <name> | parmindex <#> | <#>] |
\end_layout

\begin_layout LyX-Code
<var> in <list> |
\end_layout

\begin_layout LyX-Code
<var> oversets <list> |
\end_layout

\begin_layout LyX-Code
<var> datasetblocks <set> blocksize <#> [blockoffset <#>]
\end_layout

\begin_layout LyX-Code
[cumulative [firstblock <#>]] |
\end_layout

\begin_layout LyX-Code
<var>=<start>;[<var><end OP><end>;]<var><increment OP>[<value>] ...
}
Expand All @@ -2087,7 +2112,7 @@ for { {atoms|residues|molecules|molfirstres|mollastres}
\end_layout

\begin_layout LyX-Code
Available 'end OP' : '<' '>'
Available 'end OP' : '<' '>' '<=' '>='
\end_layout

\begin_layout LyX-Code
Expand Down Expand Up @@ -2160,6 +2185,65 @@ in
File name wildcards can be used.
\end_layout

\begin_layout Description
<var>
\begin_inset space ~
\end_inset

oversets
\begin_inset space ~
\end_inset

<list> Loop over sets selected by comma-separated list of names.
Data set wildcards can be used.
\end_layout

\begin_layout Description
<var>
\begin_inset space ~
\end_inset

datasetblocks
\begin_inset space ~
\end_inset

<set> Loop over blocks in specified DataSet.
\end_layout

\begin_deeper
\begin_layout Description
blocksize
\begin_inset space ~
\end_inset

<#> Size of blocks to use.
\end_layout

\begin_layout Description
[blockoffset
\begin_inset space ~
\end_inset

<#>] Offset between blocks.
\end_layout

\begin_layout Description
[cumulative] Instead of blocks of fixed size, use blocks of increasing size
incremented by blocksize.
\end_layout

\begin_deeper
\begin_layout Description
[firstblock
\begin_inset space ~
\end_inset

<#>] When cumulative, the size of the first block (default is first data
set element).
\end_layout

\end_deeper
\end_deeper
\begin_layout Description
<var>=<start>;[<var><end
\begin_inset space ~
Expand Down Expand Up @@ -2188,11 +2272,32 @@ OP>[<value>] Loop over integer script variable
.
\end_layout

\begin_layout Standard
Data Sets Created (datasetblocks loops):
\end_layout

\begin_layout Description
<var>[block]:<start
\begin_inset space \space{}
\end_inset

idx> (Data set blocks only) Data set block of blocksize starting at <start
idx>.
\end_layout

\begin_layout Description
<var>[cumul]:<end
\begin_inset space ~
\end_inset

idx> (Cumulative data set blocks only) Data set block starting at firstblock
and ending at <end idx>.
\end_layout

\end_deeper
\begin_layout Standard
Create a for loop using one or more mask expressions or integers.
Loops can be nested, but currently inner loops cannot refer to output loop
variables.
Create a for loop using one or more mask expressions, integers, etc.
Loops can be nested inside each other.
Integer loops may be used without an end condition, but in that case at
least one descriptor in the loop should have an end condition or refer
to a mask.
Expand All @@ -2201,16 +2306,13 @@ Create a for loop using one or more mask expressions or integers.
done
\series default
keyword.
Note that unlike C-style for loops the variable is not incremented on the
final execution, so the final value of
\series bold
<var>
\series default
will be
\series bold
<end>
\series default
(or the last selection in the mask).

\end_layout

\begin_layout Standard
Note that non-integer variables (e.g.
'inmask' loops) are NOT incremented after the final loop iteration, i.e.
these loop variables always retain their final value.
\end_layout

\begin_layout Standard
Expand Down Expand Up @@ -2383,8 +2485,24 @@ trajin
\end_deeper
\begin_layout Standard
Set (<OP> = '=') or append (<OP> = '+=') a script variable.
Script variables are referred to in CPPTRAJ input by using a dollar sign
'$' prefix.
Script variables are character strings, and are referred to in CPPTRAJ
input by using a dollar sign '$' prefix.
\end_layout

\begin_layout Standard
For example, the following input will load files my.parm7 and my.rst7:
\end_layout

\begin_layout LyX-Code
set PREFIX = my
\end_layout

\begin_layout LyX-Code
trajin $PREFIX.parm7
\end_layout

\begin_layout LyX-Code
trajin $PREFIX.rst7
\end_layout

\begin_layout Standard
Expand Down Expand Up @@ -2413,11 +2531,13 @@ show
\end_layout

\begin_layout LyX-Code
show
show [<var1> ...]
\end_layout

\begin_layout Standard
Show all current script variables and their values.
If no variable names specified, show all current script variables and their
values.
Otherwise, show the values of the specified script variables.
\end_layout

\begin_layout Section
Expand Down Expand Up @@ -4918,7 +5038,7 @@ Write
\end_layout

\begin_layout LyX-Code
[invert] [xydy]
[invert] [xydy] [<label set>]
\begin_inset Separator latexpar
\end_inset

Expand All @@ -4937,6 +5057,14 @@ invert Normally, data is written out with X-values pertaining to frames
xydy Combine consecutive pairs of sets into XYDY sets.
\end_layout

\begin_layout Description
<label
\begin_inset space ~
\end_inset

set> If a string dataset is specified, assume it has data point labels.
\end_layout

\end_deeper
\begin_layout Standard
If a single string data set is specified when writing Grace format, it is
Expand Down
1 change: 1 addition & 0 deletions src/Action_InfraredSpectrum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "ProgressBar.h"
#include "Constants.h"
#include "DataSet_double.h"
#include "DataSet_Vector.h"
#include "Corr.h"
#ifdef _OPENMP
# include <omp.h>
Expand Down
5 changes: 2 additions & 3 deletions src/Action_InfraredSpectrum.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef INC_ACTION_INFRAREDSPECTRUM_H
#define INC_ACTION_INFRAREDSPECTRUM_H
#include "Action.h"
#include "DataSet_Vector.h"
class DataSet_Vector;
/// <Enter description of Action_InfraredSpectrum here>
class Action_InfraredSpectrum : public Action {
public:
Expand All @@ -14,8 +14,7 @@ class Action_InfraredSpectrum : public Action {
Action::RetType DoAction(int, ActionFrame&);
void Print();

typedef DataSet_Vector VelArray;
VelArray* Vel_; ///< Hold velocity*charge for selected atoms at each frame.
DataSet_Vector* Vel_; ///< Hold velocity*charge for selected atoms at each frame.
DataSet* VAC_;
AtomMask mask_; ///< Atoms to calculate VAC fn for.
Topology* currentTop_;
Expand Down
2 changes: 1 addition & 1 deletion src/Action_Matrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ Action::RetType Action_Matrix::Init(ArgList& actionArgs, ActionInit& init, int d
return Action::ERR;
}
for ( DataSetList::const_iterator DS = init.DSL().begin(); DS != init.DSL().end(); ++DS) {
if ( (*DS)->Type() == DataSet::VECTOR && (*DS)->Meta().ScalarType() == MetaData::IREDVEC )
if ( (*DS)->Group() == DataSet::VECTOR_1D && (*DS)->Meta().ScalarType() == MetaData::IREDVEC )
IredVectors_.push_back( (DataSet_Vector*)*DS );
}
if (IredVectors_.empty()) {
Expand Down
3 changes: 2 additions & 1 deletion src/Action_MultiVector.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "Action_MultiVector.h"
#include "CpptrajStdio.h"
#include "DataSet_Vector.h"

Action_MultiVector::Action_MultiVector() :
debug_(0),
Expand Down Expand Up @@ -120,7 +121,7 @@ Action::RetType Action_MultiVector::DoAction(int frameNum, ActionFrame& frm) {
Vec3 CXYZ( frm.Frm().CRD( CrdIdx1_[nv] ) );
Vec3 VXYZ( frm.Frm().CRD( CrdIdx2_[nv] ) );
VXYZ -= CXYZ;
data_[nv]->AddVxyz(VXYZ, CXYZ);
data_[nv]->AddVxyzo(VXYZ, CXYZ);
}

return Action::OK;
Expand Down
2 changes: 1 addition & 1 deletion src/Action_MultiVector.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#ifndef INC_MULTIVECTOR_H
#define INC_MULTIVECTOR_H
#include "Action.h"
#include "DataSet_Vector.h"
#include "Range.h"
class DataSet_Vector;
class Action_MultiVector : public Action {
public:
Action_MultiVector();
Expand Down
3 changes: 2 additions & 1 deletion src/Action_Principal.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "Action_Principal.h"
#include "CpptrajStdio.h"
#include "Matrix_3x3.h"
#include "DataSet_Mat3x3.h"
#include "DataSet_Vector.h"

// CONSTRUCTOR
Action_Principal::Action_Principal() :
Expand Down
4 changes: 2 additions & 2 deletions src/Action_Principal.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#ifndef INC_ACTION_PRINCIPAL_H
#define INC_ACTION_PRINCIPAL_H
#include "Action.h"
#include "DataSet_Mat3x3.h"
#include "DataSet_Vector.h"
class DataSet_Mat3x3;
class DataSet_Vector;
class Action_Principal : public Action {
public:
Action_Principal();
Expand Down
7 changes: 6 additions & 1 deletion src/Action_Rmsd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "CpptrajStdio.h"
#include "StringRoutines.h" // integerToString
#include "DataSet_Mesh.h"
#include "DataSet_Vector.h"

// CONSTRUCTOR
Action_Rmsd::Action_Rmsd() :
Expand Down Expand Up @@ -123,6 +124,10 @@ Action::RetType Action_Rmsd::Init(ArgList& actionArgs, ActionInit& init, int deb
return Action::ERR;
}
tvecs_ = (DataSet_Vector*)init.DSL().AddSet(DataSet::VECTOR, md);
//if (tvecType_ == COMBINED)
// tvecs_ = (DataSet_Vector*)init.DSL().AddSet(DataSet::VEC_XYZ, md);
//else // SEPARATE
// tvecs_ = (DataSet_Vector*)init.DSL().AddSet(DataSet::VEC_OXYZ, md);
if (tvecs_ == 0) return Action::ERR;
if (vecsOut != 0) vecsOut->AddDataSet( tvecs_ );
}
Expand Down Expand Up @@ -373,7 +378,7 @@ Action::RetType Action_Rmsd::DoAction(int frameNum, ActionFrame& frm) {
if (tvecType_ == COMBINED)
tvecs_->AddVxyz( tgtTrans_ + REF_.RefTrans() );
else if (tvecType_ == SEPARATE)
tvecs_->AddVxyz( tgtTrans_, REF_.RefTrans() );
tvecs_->AddVxyzo( tgtTrans_, REF_.RefTrans() );
switch (mode_) {
case ROT_AND_TRANS:
frm.ModifyFrm().Trans_Rot_Trans(tgtTrans_, rot_, REF_.RefTrans());
Expand Down
Loading

0 comments on commit 12a3360

Please sign in to comment.