From a2aa220025758ec21d649c7b79fc0687b629e2e6 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Fri, 2 Feb 2024 16:04:02 -0500 Subject: [PATCH 1/3] Add --charge command line flag --- src/Cpptraj.cpp | 34 ++++++++++++++++++++++++++++++++++ src/Cpptraj.h | 2 ++ 2 files changed, 36 insertions(+) diff --git a/src/Cpptraj.cpp b/src/Cpptraj.cpp index 23aa89f0a7..712953bfc2 100644 --- a/src/Cpptraj.cpp +++ b/src/Cpptraj.cpp @@ -96,6 +96,7 @@ void Cpptraj::Usage() { "\t-mr : Print selected residue numbers to STDOUT.\n" "\t--mask : Print detailed atom selection to STDOUT.\n" "\t--resmask : Print detailed residue selection to STDOUT.\n" + "\t--charge : Print total charge in e- of atoms selected by .\n" "\t--rng : Change default random number generator.\n" " * Denotes flag may be specified multiple times.\n" "\n", CpptrajState::RngKeywords()); @@ -273,6 +274,35 @@ std::string Cpptraj::Defines() { return defined_str; } +/** Calculate the total charge from the command line. */ +int Cpptraj::CalcCharge(Sarray const& topFiles, std::string const& maskexpr) +const +{ + SetWorldSilent(true); + if (maskexpr.empty()) { + mprinterr("Error: No mask given for '--charge'.\n"); + return 1; + } + if (topFiles.empty()) { + mprinterr("Error: No topology file specified.\n"); + return 1; + } + ParmFile pfile; + Topology parm; + if (pfile.ReadTopology(parm, topFiles[0], State_.Debug())) return 1; + AtomMask tempMask( maskexpr ); + if (parm.SetupIntegerMask( tempMask )) return 1; + if (tempMask.None()) { + mprinterr("Error: Nothing selected by mask '%s'\n", maskexpr.c_str()); + return 1; + } + double qtotal = 0; + for (AtomMask::const_iterator it = tempMask.begin(); it != tempMask.end(); ++it) + qtotal += parm[*it].Charge(); + loudPrintf("%g\n", qtotal); + return 0; +} + /** Process a mask from the command line. */ int Cpptraj::ProcessMask( Sarray const& topFiles, Sarray const& refFiles, std::string const& maskexpr, @@ -521,6 +551,10 @@ Cpptraj::Mode Cpptraj::ProcessCmdLineArgs(int argc, char** argv) { // --resmask: Parse mask string, print selected residue details if (ProcessMask( topFiles, refFiles, cmdLineArgs[++iarg], true, true )) return ERROR; return QUIT; + } else if ( NotFinalArg(cmdLineArgs, "--charge", iarg) ) { + // --charge: Print the total charge of atoms selected by the mask + if (CalcCharge( topFiles, cmdLineArgs[++iarg])) return ERROR; + return QUIT; } else if ( NotFinalArg(cmdLineArgs, "--rng", iarg) ) { // --rng: Change default RNG if (State_.ChangeDefaultRng( cmdLineArgs[++iarg] )) return ERROR; diff --git a/src/Cpptraj.h b/src/Cpptraj.h index bfa55c0a5c..e125ab2327 100644 --- a/src/Cpptraj.h +++ b/src/Cpptraj.h @@ -20,6 +20,8 @@ class Cpptraj { static void Finalize(); static inline void AddArgs(Sarray&, ArgList const&, int&); static inline void ResizeArgs(Sarray const&, Sarray&, const char*); + /// Calculate total charge from command line + int CalcCharge(Sarray const&, std::string const&) const; int ProcessMask(Sarray const&, Sarray const&, std::string const&, bool,bool) const; Mode ProcessCmdLineArgs(int, char**); int Interactive(); From fb5e36d62ce69d90575dcab601a5f8b98b6a1bab Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Fri, 2 Feb 2024 16:04:29 -0500 Subject: [PATCH 2/3] 6.23.2. Revision bump for --charge command line flag --- src/Version.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Version.h b/src/Version.h index f4faf6227f..1b3bb433bb 100644 --- a/src/Version.h +++ b/src/Version.h @@ -12,7 +12,7 @@ * Whenever a number that precedes is incremented, all subsequent * numbers should be reset to 0. */ -#define CPPTRAJ_INTERNAL_VERSION "V6.23.1" +#define CPPTRAJ_INTERNAL_VERSION "V6.23.2" /// PYTRAJ relies on this #define CPPTRAJ_VERSION_STRING CPPTRAJ_INTERNAL_VERSION #endif From a663c9e3435e213a3ac1b01b08440e6e9e1b0272 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Fri, 2 Feb 2024 16:06:54 -0500 Subject: [PATCH 3/3] Add help text, add manual entry. --- doc/cpptraj.lyx | 28 ++++++++++++++++++++++++---- src/Cpptraj.cpp | 4 ++-- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/doc/cpptraj.lyx b/doc/cpptraj.lyx index fbcbeccff2..0c372e355a 100644 --- a/doc/cpptraj.lyx +++ b/doc/cpptraj.lyx @@ -419,7 +419,7 @@ cpptraj [-p ] [-i ] [-y ] [-x ] \end_layout \begin_layout LyX-Code - [--rng {marsaglia|stdlib|mt|pcg32|xo128}] + [--rng {marsaglia|stdlib|mt|pcg32|xo128}] [--charge ] \end_layout \begin_deeper @@ -580,7 +580,11 @@ cpptraj [-p ] [-i ] [-y ] [-x ] \end_layout \begin_layout Description --mr : Print selected residue numbers to STDOUT. +-mr +\begin_inset space ~ +\end_inset + + : Print selected residue numbers to STDOUT. Selected residues are written out as 'Selected= 1 2 3 ...' \end_layout @@ -593,11 +597,27 @@ cpptraj [-p ] [-i ] [-y ] [-x ] \end_layout \begin_layout Description -–resmask : Print detailed residue selection to STDOUT. +–resmask +\begin_inset space ~ +\end_inset + + Print detailed residue selection to STDOUT. \end_layout \begin_layout Description ---rng : Change default random number generator. +--rng +\begin_inset space ~ +\end_inset + + Change default random number generator. +\end_layout + +\begin_layout Description +--charge +\begin_inset space ~ +\end_inset + + Print total charge (in e-) of atoms selected by to STDOUT. \end_layout \end_deeper diff --git a/src/Cpptraj.cpp b/src/Cpptraj.cpp index 712953bfc2..c59b25f478 100644 --- a/src/Cpptraj.cpp +++ b/src/Cpptraj.cpp @@ -73,7 +73,7 @@ void Cpptraj::Usage() { " [-h | --help] [-V | --version] [--defines] [-debug <#>]\n" " [--interactive] [--log ] [-tl]\n" " [-ms ] [-mr ] [--mask ] [--resmask ]\n" - " [--rng %s]\n" + " [--rng %s] [--charge ]\n" "\t-p : * Load as a topology file.\n" "\t-i : * Read input from file .\n" "\t-y : * Read from trajectory file ; same as input 'trajin '.\n" @@ -96,8 +96,8 @@ void Cpptraj::Usage() { "\t-mr : Print selected residue numbers to STDOUT.\n" "\t--mask : Print detailed atom selection to STDOUT.\n" "\t--resmask : Print detailed residue selection to STDOUT.\n" - "\t--charge : Print total charge in e- of atoms selected by .\n" "\t--rng : Change default random number generator.\n" + "\t--charge : Print total charge in e- of atoms selected by .\n" " * Denotes flag may be specified multiple times.\n" "\n", CpptrajState::RngKeywords()); }