From 270f2279805bff217cffd10386aea494b9dfc8b6 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Mon, 21 Aug 2023 15:17:52 -0400 Subject: [PATCH 01/10] Start adding change mass command. --- src/Exec_Change.cpp | 28 +++++++++++++++++++++++++++- src/Exec_Change.h | 1 + 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/Exec_Change.cpp b/src/Exec_Change.cpp index 7da6f0956a..d732e60bc0 100644 --- a/src/Exec_Change.cpp +++ b/src/Exec_Change.cpp @@ -26,7 +26,8 @@ Exec::RetType Exec_Change::Execute(CpptrajState& State, ArgList& argIn) { // Change type enum ChangeType { UNKNOWN = 0, RESNAME, CHAINID, ORESNUMS, ICODES, - ATOMNAME, ADDBOND, REMOVEBONDS, SPLITRES, BONDPARM }; + ATOMNAME, ADDBOND, REMOVEBONDS, SPLITRES, BONDPARM, + MASS }; ChangeType type = UNKNOWN; if (argIn.hasKey("resname")) type = RESNAME; @@ -46,6 +47,8 @@ Exec::RetType Exec_Change::Execute(CpptrajState& State, ArgList& argIn) type = BONDPARM; else if (argIn.hasKey("splitres")) type = SPLITRES; + else if (argIn.hasKey("mass")) + type = MASS; if (type == UNKNOWN) { mprinterr("Error: No change type specified.\n"); return CpptrajState::ERR; @@ -77,6 +80,7 @@ Exec::RetType Exec_Change::Execute(CpptrajState& State, ArgList& argIn) case REMOVEBONDS : err = RemoveBonds(State, *parm, argIn); break; case BONDPARM : err = ChangeBondParameters(*parm, argIn); break; case SPLITRES : err = ChangeSplitRes(*parm, argIn); break; + case MASS : err = ChangeMass(*parm, argIn, State.DSL()); break; case UNKNOWN : err = 1; // sanity check } if (err != 0) return CpptrajState::ERR; @@ -590,5 +594,27 @@ int Exec_Change::ChangeBondParameters(Topology& topIn, ArgList& argIn) const { topIn.AddBond(it->A1(), it->A2(), bp); } + return 0; +} + +/** Change mass in topology */ +int Exec_Change::ChangeMass(Topology& topIn, ArgList& argIn, DataSetList const& DSL) +const +{ + std::string maskExpression = argIn.GetStringKey("of"); + AtomMask atomsToChange; + if (atomsToChange.SetMaskString( maskExpression )) { + mprinterr("Error: Could not set mask expression.\n"); + return 1; + } + if (topIn.SetupIntegerMask( atomsToChange )) { + mprinterr("Error: Could not set up mask.\n"); + return 1; + } + if (atomsToChange.None()) { + mprintf("Warning: Mask '%s' selects no atoms.\n", atomsToChange.MaskString()); + return 0; + } + return 0; } diff --git a/src/Exec_Change.h b/src/Exec_Change.h index 3ab3b6dd61..bf847ee38f 100644 --- a/src/Exec_Change.h +++ b/src/Exec_Change.h @@ -21,5 +21,6 @@ class Exec_Change : public Exec { int AddBond(Topology&, ArgList&) const; int RemoveBonds(CpptrajState&, Topology&, ArgList&) const; int ChangeBondParameters(Topology&, ArgList&) const; + int ChangeMass(Topology&, ArgList&, DataSetList const&) const; }; #endif From 956bc89797f5c63932673ae733c5e28a54958c5d Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Mon, 21 Aug 2023 16:06:26 -0400 Subject: [PATCH 02/10] Finish initial incarnation of change mass --- src/Exec_Change.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ src/cpptrajdepend | 2 +- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/Exec_Change.cpp b/src/Exec_Change.cpp index d732e60bc0..950fab5915 100644 --- a/src/Exec_Change.cpp +++ b/src/Exec_Change.cpp @@ -3,6 +3,7 @@ #include "CpptrajStdio.h" #include "TypeNameHolder.h" #include "ParameterTypes.h" +#include "DataSet_1D.h" // Exec_Change::Help() void Exec_Change::Help() const @@ -615,6 +616,45 @@ const mprintf("Warning: Mask '%s' selects no atoms.\n", atomsToChange.MaskString()); return 0; } + atomsToChange.MaskInfo(); + + std::string fromSet = argIn.GetStringKey("fromset"); + if (!fromSet.empty()) { + DataSet* ds = DSL.GetDataSet( fromSet ); + if (ds == 0) { + mprinterr("Error: No set selected by '%s'\n", fromSet.c_str()); + return 1; + } + if (ds->Group() != DataSet::SCALAR_1D) { + mprinterr("Error: Data set '%s' is not scalar 1D.\n", ds->legend()); + return 1; + } + if (ds->Size() != (unsigned int)atomsToChange.Nselected()) { + mprinterr("Error: %i atoms to change mass of, but set '%s' has %zu elements.\n", + atomsToChange.Nselected(), ds->Size()); + return 1; + } + DataSet_1D const& dset = static_cast( *ds ); + for (int idx = 0; idx != atomsToChange.Nselected(); idx++) { + Atom& currentAtom = topIn.SetAtom( atomsToChange[idx] ); + mprintf("\tChanging mass of atom '%s' from %g to %g\n", + topIn.AtomMaskName(atomsToChange[idx]).c_str(), + currentAtom.Mass(), dset.Dval(idx)); + currentAtom.SetMass( dset.Dval(idx) ); + } + } else { + if (!argIn.Contains("to")) { + mprinterr("Error: Expected either 'fromset' or 'to' for 'change mass'.\n"); + return 1; + } + double newMass = argIn.getKeyDouble("to", 0.0); + for (AtomMask::const_iterator at = atomsToChange.begin(); at != atomsToChange.end(); ++at) { + Atom& currentAtom = topIn.SetAtom( *at ); + mprintf("\tChanging mass of atom '%s' from %g to %g\n", topIn.AtomMaskName(*at).c_str(), + currentAtom.Mass(), newMass); + currentAtom.SetMass( newMass ); + } + } return 0; } diff --git a/src/cpptrajdepend b/src/cpptrajdepend index f08f79a7a3..322b7e0562 100644 --- a/src/cpptrajdepend +++ b/src/cpptrajdepend @@ -283,7 +283,7 @@ Exec_AddMissingRes.o : Exec_AddMissingRes.cpp Action.h ActionFrameCounter.h Acti Exec_Analyze.o : Exec_Analyze.cpp Action.h ActionList.h ActionState.h Analysis.h AnalysisList.h AnalysisState.h ArgList.h AssociatedData.h Atom.h AtomMask.h AtomType.h BaseIOtype.h Box.h Cmd.h CmdList.h Command.h Constants.h CoordinateInfo.h CpptrajFile.h CpptrajState.h CpptrajStdio.h DataFile.h DataFileList.h DataSet.h DataSetList.h DataSet_Coords.h DataSet_Coords_REF.h Dimension.h DispatchObject.h EnsembleIn.h EnsembleOutList.h Exec.h Exec_Analyze.h FileIO.h FileName.h FileTypes.h Frame.h FramePtrArray.h InputTrajCommon.h MaskToken.h Matrix_3x3.h MetaData.h Molecule.h NameType.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h Range.h ReferenceFrame.h ReplicaDimArray.h ReplicaInfo.h Residue.h Segment.h SymbolExporting.h TextFormat.h Timer.h Topology.h TrajFrameCounter.h Trajin.h TrajinList.h TrajoutList.h TypeNameHolder.h Unit.h Vec3.h Exec_Calc.o : Exec_Calc.cpp Action.h ActionList.h ActionState.h Analysis.h AnalysisList.h AnalysisState.h ArgList.h AssociatedData.h Atom.h AtomMask.h AtomType.h BaseIOtype.h Box.h Constants.h CoordinateInfo.h CpptrajFile.h CpptrajState.h CpptrajStdio.h DataFile.h DataFileList.h DataSet.h DataSetList.h DataSet_Coords.h DataSet_Coords_REF.h Dimension.h DispatchObject.h EnsembleIn.h EnsembleOutList.h Exec.h Exec_Calc.h FileIO.h FileName.h FileTypes.h Frame.h FramePtrArray.h InputTrajCommon.h MaskToken.h Matrix_3x3.h MetaData.h Molecule.h NameType.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h RPNcalc.h Range.h ReferenceFrame.h ReplicaDimArray.h ReplicaInfo.h Residue.h Segment.h SymbolExporting.h TextFormat.h Timer.h Topology.h TrajFrameCounter.h Trajin.h TrajinList.h TrajoutList.h TypeNameHolder.h Unit.h Vec3.h Exec_CatCrd.o : Exec_CatCrd.cpp Action.h ActionList.h ActionState.h Analysis.h AnalysisList.h AnalysisState.h ArgList.h AssociatedData.h Atom.h AtomMask.h AtomType.h BaseIOtype.h Box.h Constants.h CoordinateInfo.h CpptrajFile.h CpptrajState.h CpptrajStdio.h DataFile.h DataFileList.h DataSet.h DataSetList.h DataSet_Coords.h DataSet_Coords_REF.h Dimension.h DispatchObject.h EnsembleIn.h EnsembleOutList.h Exec.h Exec_CatCrd.h FileIO.h FileName.h FileTypes.h Frame.h FramePtrArray.h InputTrajCommon.h MaskToken.h Matrix_3x3.h MetaData.h Molecule.h NameType.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h Range.h ReferenceFrame.h ReplicaDimArray.h ReplicaInfo.h Residue.h Segment.h SymbolExporting.h TextFormat.h Timer.h Topology.h TrajFrameCounter.h Trajin.h TrajinList.h TrajoutList.h TypeNameHolder.h Unit.h Vec3.h -Exec_Change.o : Exec_Change.cpp Action.h ActionList.h ActionState.h Analysis.h AnalysisList.h AnalysisState.h ArgList.h AssociatedData.h Atom.h AtomMask.h AtomType.h BaseIOtype.h Box.h CharMask.h Constants.h CoordinateInfo.h CpptrajFile.h CpptrajState.h CpptrajStdio.h DataFile.h DataFileList.h DataSet.h DataSetList.h DataSet_Coords.h DataSet_Coords_REF.h Dimension.h DispatchObject.h EnsembleIn.h EnsembleOutList.h Exec.h Exec_Change.h FileIO.h FileName.h FileTypes.h Frame.h FramePtrArray.h InputTrajCommon.h MaskToken.h Matrix_3x3.h MetaData.h Molecule.h NameType.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h Range.h ReferenceFrame.h ReplicaDimArray.h ReplicaInfo.h Residue.h Segment.h SymbolExporting.h TextFormat.h Timer.h Topology.h TrajFrameCounter.h Trajin.h TrajinList.h TrajoutList.h TypeNameHolder.h Unit.h Vec3.h +Exec_Change.o : Exec_Change.cpp Action.h ActionList.h ActionState.h Analysis.h AnalysisList.h AnalysisState.h ArgList.h AssociatedData.h Atom.h AtomMask.h AtomType.h BaseIOtype.h Box.h CharMask.h Constants.h CoordinateInfo.h CpptrajFile.h CpptrajState.h CpptrajStdio.h DataFile.h DataFileList.h DataSet.h DataSetList.h DataSet_1D.h DataSet_Coords.h DataSet_Coords_REF.h Dimension.h DispatchObject.h EnsembleIn.h EnsembleOutList.h Exec.h Exec_Change.h FileIO.h FileName.h FileTypes.h Frame.h FramePtrArray.h InputTrajCommon.h MaskToken.h Matrix_3x3.h MetaData.h Molecule.h NameType.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h Range.h ReferenceFrame.h ReplicaDimArray.h ReplicaInfo.h Residue.h Segment.h SymbolExporting.h TextFormat.h Timer.h Topology.h TrajFrameCounter.h Trajin.h TrajinList.h TrajoutList.h TypeNameHolder.h Unit.h Vec3.h Exec_ClusterMap.o : Exec_ClusterMap.cpp Action.h ActionList.h ActionState.h Analysis.h AnalysisList.h AnalysisState.h ArgList.h ArrayIterator.h AssociatedData.h Atom.h AtomMask.h AtomType.h BaseIOtype.h Box.h ClusterMap.h Constants.h CoordinateInfo.h CpptrajFile.h CpptrajState.h CpptrajStdio.h DataFile.h DataFileList.h DataSet.h DataSetList.h DataSet_2D.h DataSet_Coords.h DataSet_Coords_REF.h DataSet_MatrixFlt.h Dimension.h DispatchObject.h EnsembleIn.h EnsembleOutList.h Exec.h Exec_ClusterMap.h FileIO.h FileName.h FileTypes.h Frame.h FramePtrArray.h InputTrajCommon.h MaskToken.h Matrix.h Matrix_3x3.h MetaData.h Molecule.h NameType.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h Range.h ReferenceFrame.h ReplicaDimArray.h ReplicaInfo.h Residue.h Segment.h SymbolExporting.h TextFormat.h Timer.h Topology.h TrajFrameCounter.h Trajin.h TrajinList.h TrajoutList.h TypeNameHolder.h Unit.h Vec3.h Exec_CombineCoords.o : Exec_CombineCoords.cpp Action.h ActionList.h ActionState.h Analysis.h AnalysisList.h AnalysisState.h ArgList.h AssociatedData.h Atom.h AtomMask.h AtomType.h BaseIOtype.h Box.h Constants.h CoordinateInfo.h CpptrajFile.h CpptrajState.h CpptrajStdio.h DataFile.h DataFileList.h DataSet.h DataSetList.h DataSet_Coords.h DataSet_Coords_REF.h Dimension.h DispatchObject.h EnsembleIn.h EnsembleOutList.h Exec.h Exec_CombineCoords.h FileIO.h FileName.h FileTypes.h Frame.h FramePtrArray.h InputTrajCommon.h MaskToken.h Matrix_3x3.h MetaData.h Molecule.h NameType.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h Range.h ReferenceFrame.h ReplicaDimArray.h ReplicaInfo.h Residue.h Segment.h SymbolExporting.h TextFormat.h Timer.h Topology.h TrajFrameCounter.h Trajin.h TrajinList.h TrajoutList.h TypeNameHolder.h Unit.h Vec3.h Exec_Commands.o : Exec_Commands.cpp Action.h ActionList.h ActionState.h Analysis.h AnalysisList.h AnalysisState.h ArgList.h AssociatedData.h Atom.h AtomMask.h AtomType.h BaseIOtype.h Box.h Constants.h CoordinateInfo.h CpptrajFile.h CpptrajState.h CpptrajStdio.h DataFile.h DataFileList.h DataSet.h DataSetList.h DataSet_Coords.h DataSet_Coords_REF.h Dimension.h DispatchObject.h EnsembleIn.h EnsembleOutList.h Exec.h Exec_Commands.h FileIO.h FileName.h FileTypes.h Frame.h FramePtrArray.h InputTrajCommon.h MaskToken.h Matrix_3x3.h MetaData.h Molecule.h NameType.h Parallel.h ParameterHolders.h ParameterSet.h ParameterTypes.h Range.h ReferenceFrame.h ReplicaDimArray.h ReplicaInfo.h Residue.h Segment.h SymbolExporting.h TextFormat.h Timer.h Topology.h TrajFrameCounter.h Trajin.h TrajinList.h TrajoutList.h TypeNameHolder.h Unit.h Vec3.h From 321ba3add3d57900332288ca8143afa3f08fde9a Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Wed, 23 Aug 2023 08:55:35 -0400 Subject: [PATCH 03/10] Add change mass test --- test/Test_Change/AFV.zeroHmass.dat.save | 50 +++++++++++++++++++++++++ test/Test_Change/RunTest.sh | 12 +++++- 2 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 test/Test_Change/AFV.zeroHmass.dat.save diff --git a/test/Test_Change/AFV.zeroHmass.dat.save b/test/Test_Change/AFV.zeroHmass.dat.save new file mode 100644 index 0000000000..910b275db2 --- /dev/null +++ b/test/Test_Change/AFV.zeroHmass.dat.save @@ -0,0 +1,50 @@ +#Atom Name #Res Name #Mol Type Charge Mass GBradius El rVDW eVDW + 1 N 1 ALA 1 N3 0.1414 14.0100 1.5500 N 1.8240 0.1700 + 2 H1 1 ALA 1 H 0.1997 0.0000 1.3000 H 0.6000 0.0157 + 3 H2 1 ALA 1 H 0.1997 0.0000 1.3000 H 0.6000 0.0157 + 4 H3 1 ALA 1 H 0.1997 0.0000 1.3000 H 0.6000 0.0157 + 5 CA 1 ALA 1 CX 0.0962 12.0100 1.7000 C 1.9080 0.1094 + 6 HA 1 ALA 1 HP 0.0889 0.0000 1.3000 H 1.1000 0.0157 + 7 CB 1 ALA 1 CT -0.0597 12.0100 1.7000 C 1.9080 0.1094 + 8 HB1 1 ALA 1 HC 0.0300 0.0000 1.3000 H 1.4870 0.0157 + 9 HB2 1 ALA 1 HC 0.0300 0.0000 1.3000 H 1.4870 0.0157 + 10 HB3 1 ALA 1 HC 0.0300 0.0000 1.3000 H 1.4870 0.0157 + 11 C 1 ALA 1 C 0.6163 12.0100 1.7000 C 1.9080 0.0860 + 12 O 1 ALA 1 O -0.5722 16.0000 1.5000 O 1.6612 0.2100 + 13 N 2 PHE 1 N -0.4157 14.0100 1.5500 N 1.8240 0.1700 + 14 H 2 PHE 1 H 0.2719 0.0000 1.3000 H 0.6000 0.0157 + 15 CA 2 PHE 1 CX -0.0024 12.0100 1.7000 C 1.9080 0.1094 + 16 HA 2 PHE 1 H1 0.0978 0.0000 1.3000 H 1.3870 0.0157 + 17 CB 2 PHE 1 CT -0.0343 12.0100 1.7000 C 1.9080 0.1094 + 18 HB2 2 PHE 1 HC 0.0295 0.0000 1.3000 H 1.4870 0.0157 + 19 HB3 2 PHE 1 HC 0.0295 0.0000 1.3000 H 1.4870 0.0157 + 20 CG 2 PHE 1 CA 0.0118 12.0100 1.7000 C 1.9080 0.0860 + 21 CD1 2 PHE 1 CA -0.1256 12.0100 1.7000 C 1.9080 0.0860 + 22 HD1 2 PHE 1 HA 0.1330 0.0000 1.3000 H 1.4590 0.0150 + 23 CE1 2 PHE 1 CA -0.1704 12.0100 1.7000 C 1.9080 0.0860 + 24 HE1 2 PHE 1 HA 0.1430 0.0000 1.3000 H 1.4590 0.0150 + 25 CZ 2 PHE 1 CA -0.1072 12.0100 1.7000 C 1.9080 0.0860 + 26 HZ 2 PHE 1 HA 0.1297 0.0000 1.3000 H 1.4590 0.0150 + 27 CE2 2 PHE 1 CA -0.1704 12.0100 1.7000 C 1.9080 0.0860 + 28 HE2 2 PHE 1 HA 0.1430 0.0000 1.3000 H 1.4590 0.0150 + 29 CD2 2 PHE 1 CA -0.1256 12.0100 1.7000 C 1.9080 0.0860 + 30 HD2 2 PHE 1 HA 0.1330 0.0000 1.3000 H 1.4590 0.0150 + 31 C 2 PHE 1 C 0.5973 12.0100 1.7000 C 1.9080 0.0860 + 32 O 2 PHE 1 O -0.5679 16.0000 1.5000 O 1.6612 0.2100 + 33 N 3 VAL 1 N -0.3821 14.0100 1.5500 N 1.8240 0.1700 + 34 H 3 VAL 1 H 0.2681 0.0000 1.3000 H 0.6000 0.0157 + 35 CA 3 VAL 1 CX -0.3438 12.0100 1.7000 C 1.9080 0.1094 + 36 HA 3 VAL 1 H1 0.1438 0.0000 1.3000 H 1.3870 0.0157 + 37 CB 3 VAL 1 CT 0.1940 12.0100 1.7000 C 1.9080 0.1094 + 38 HB 3 VAL 1 HC 0.0308 0.0000 1.3000 H 1.4870 0.0157 + 39 CG1 3 VAL 1 CT -0.3064 12.0100 1.7000 C 1.9080 0.1094 + 40 HG11 3 VAL 1 HC 0.0836 0.0000 1.3000 H 1.4870 0.0157 + 41 HG12 3 VAL 1 HC 0.0836 0.0000 1.3000 H 1.4870 0.0157 + 42 HG13 3 VAL 1 HC 0.0836 0.0000 1.3000 H 1.4870 0.0157 + 43 CG2 3 VAL 1 CT -0.3064 12.0100 1.7000 C 1.9080 0.1094 + 44 HG21 3 VAL 1 HC 0.0836 0.0000 1.3000 H 1.4870 0.0157 + 45 HG22 3 VAL 1 HC 0.0836 0.0000 1.3000 H 1.4870 0.0157 + 46 HG23 3 VAL 1 HC 0.0836 0.0000 1.3000 H 1.4870 0.0157 + 47 C 3 VAL 1 C 0.8350 12.0100 1.7000 C 1.9080 0.0860 + 48 O 3 VAL 1 O2 -0.8173 16.0000 1.5000 O 1.6612 0.2100 + 49 OXT 3 VAL 1 O2 -0.8173 16.0000 1.5000 O 1.6612 0.2100 diff --git a/test/Test_Change/RunTest.sh b/test/Test_Change/RunTest.sh index e519403a5d..f362d2cd6f 100755 --- a/test/Test_Change/RunTest.sh +++ b/test/Test_Change/RunTest.sh @@ -2,7 +2,8 @@ . ../MasterTest.sh -CleanFiles change.in ala3.mod.pdb ala3.chain.pdb crdala3.chain.pdb +CleanFiles change.in ala3.mod.pdb ala3.chain.pdb crdala3.chain.pdb \ + AFV.zeroHmass.dat TESTNAME='Change command test' Requires maxthreads 1 @@ -38,5 +39,14 @@ EOF RunCpptraj "Change chain ID of COORDS set test" DoTest ala3.chain.pdb.save crdala3.chain.pdb +cat > change.in < Date: Wed, 23 Aug 2023 09:05:32 -0400 Subject: [PATCH 04/10] Add change mass from data set test --- test/Test_Change/AFV.fluctMass.dat.save | 50 ++++++++++++++++++++++ test/Test_Change/RunTest.sh | 56 ++++++++++++++++++------- 2 files changed, 92 insertions(+), 14 deletions(-) create mode 100644 test/Test_Change/AFV.fluctMass.dat.save diff --git a/test/Test_Change/AFV.fluctMass.dat.save b/test/Test_Change/AFV.fluctMass.dat.save new file mode 100644 index 0000000000..d20c81fb47 --- /dev/null +++ b/test/Test_Change/AFV.fluctMass.dat.save @@ -0,0 +1,50 @@ +#Atom Name #Res Name #Mol Type Charge Mass GBradius El rVDW eVDW + 1 N 1 ALA 1 N3 0.1414 1.3392 1.5500 N 1.8240 0.1700 + 2 H1 1 ALA 1 H 0.1997 1.8307 1.3000 H 0.6000 0.0157 + 3 H2 1 ALA 1 H 0.1997 1.7955 1.3000 H 0.6000 0.0157 + 4 H3 1 ALA 1 H 0.1997 1.8237 1.3000 H 0.6000 0.0157 + 5 CA 1 ALA 1 CX 0.0962 0.8400 1.7000 C 1.9080 0.1094 + 6 HA 1 ALA 1 HP 0.0889 1.3625 1.3000 H 1.1000 0.0157 + 7 CB 1 ALA 1 CT -0.0597 1.5867 1.7000 C 1.9080 0.1094 + 8 HB1 1 ALA 1 HC 0.0300 2.0004 1.3000 H 1.4870 0.0157 + 9 HB2 1 ALA 1 HC 0.0300 2.2382 1.3000 H 1.4870 0.0157 + 10 HB3 1 ALA 1 HC 0.0300 2.0209 1.3000 H 1.4870 0.0157 + 11 C 1 ALA 1 C 0.6163 0.6606 1.7000 C 1.9080 0.0860 + 12 O 1 ALA 1 O -0.5722 1.0294 1.5000 O 1.6612 0.2100 + 13 N 2 PHE 1 N -0.4157 0.6194 1.5500 N 1.8240 0.1700 + 14 H 2 PHE 1 H 0.2719 0.9363 1.3000 H 0.6000 0.0157 + 15 CA 2 PHE 1 CX -0.0024 0.5888 1.7000 C 1.9080 0.1094 + 16 HA 2 PHE 1 H1 0.0978 0.6938 1.3000 H 1.3870 0.0157 + 17 CB 2 PHE 1 CT -0.0343 0.8447 1.7000 C 1.9080 0.1094 + 18 HB2 2 PHE 1 HC 0.0295 1.4507 1.3000 H 1.4870 0.0157 + 19 HB3 2 PHE 1 HC 0.0295 1.5059 1.3000 H 1.4870 0.0157 + 20 CG 2 PHE 1 CA 0.0118 0.3897 1.7000 C 1.9080 0.0860 + 21 CD1 2 PHE 1 CA -0.1256 1.2616 1.7000 C 1.9080 0.0860 + 22 HD1 2 PHE 1 HA 0.1330 1.9513 1.3000 H 1.4590 0.0150 + 23 CE1 2 PHE 1 CA -0.1704 1.7951 1.7000 C 1.9080 0.0860 + 24 HE1 2 PHE 1 HA 0.1430 2.5937 1.3000 H 1.4590 0.0150 + 25 CZ 2 PHE 1 CA -0.1072 1.8400 1.7000 C 1.9080 0.0860 + 26 HZ 2 PHE 1 HA 0.1297 2.4711 1.3000 H 1.4590 0.0150 + 27 CE2 2 PHE 1 CA -0.1704 1.7855 1.7000 C 1.9080 0.0860 + 28 HE2 2 PHE 1 HA 0.1430 2.5780 1.3000 H 1.4590 0.0150 + 29 CD2 2 PHE 1 CA -0.1256 1.2652 1.7000 C 1.9080 0.0860 + 30 HD2 2 PHE 1 HA 0.1330 1.9666 1.3000 H 1.4590 0.0150 + 31 C 2 PHE 1 C 0.5973 0.4730 1.7000 C 1.9080 0.0860 + 32 O 2 PHE 1 O -0.5679 0.6642 1.5000 O 1.6612 0.2100 + 33 N 3 VAL 1 N -0.3821 0.5251 1.5500 N 1.8240 0.1700 + 34 H 3 VAL 1 H 0.2681 0.7312 1.3000 H 0.6000 0.0157 + 35 CA 3 VAL 1 CX -0.3438 0.5870 1.7000 C 1.9080 0.1094 + 36 HA 3 VAL 1 H1 0.1438 1.0249 1.3000 H 1.3870 0.0157 + 37 CB 3 VAL 1 CT 0.1940 1.1005 1.7000 C 1.9080 0.1094 + 38 HB 3 VAL 1 HC 0.0308 1.5142 1.3000 H 1.4870 0.0157 + 39 CG1 3 VAL 1 CT -0.3064 1.5705 1.7000 C 1.9080 0.1094 + 40 HG11 3 VAL 1 HC 0.0836 2.1092 1.3000 H 1.4870 0.0157 + 41 HG12 3 VAL 1 HC 0.0836 2.0668 1.3000 H 1.4870 0.0157 + 42 HG13 3 VAL 1 HC 0.0836 1.8651 1.3000 H 1.4870 0.0157 + 43 CG2 3 VAL 1 CT -0.3064 1.3964 1.7000 C 1.9080 0.1094 + 44 HG21 3 VAL 1 HC 0.0836 1.9660 1.3000 H 1.4870 0.0157 + 45 HG22 3 VAL 1 HC 0.0836 1.7581 1.3000 H 1.4870 0.0157 + 46 HG23 3 VAL 1 HC 0.0836 1.6678 1.3000 H 1.4870 0.0157 + 47 C 3 VAL 1 C 0.8350 0.8819 1.7000 C 1.9080 0.0860 + 48 O 3 VAL 1 O2 -0.8173 1.3691 1.5000 O 1.6612 0.2100 + 49 OXT 3 VAL 1 O2 -0.8173 1.7206 1.5000 O 1.6612 0.2100 diff --git a/test/Test_Change/RunTest.sh b/test/Test_Change/RunTest.sh index f362d2cd6f..ec5cf1e693 100755 --- a/test/Test_Change/RunTest.sh +++ b/test/Test_Change/RunTest.sh @@ -3,14 +3,16 @@ . ../MasterTest.sh CleanFiles change.in ala3.mod.pdb ala3.chain.pdb crdala3.chain.pdb \ - AFV.zeroHmass.dat + AFV.zeroHmass.dat AFV.fluctMass.dat TESTNAME='Change command test' -Requires maxthreads 1 INPUT='-i change.in' -cat > change.in < change.in < change.in < change.in < change.in < change.in < change.in < change.in < change.in < Date: Wed, 23 Aug 2023 09:05:45 -0400 Subject: [PATCH 05/10] Report data set name --- src/Exec_Change.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Exec_Change.cpp b/src/Exec_Change.cpp index 950fab5915..6bf45ea553 100644 --- a/src/Exec_Change.cpp +++ b/src/Exec_Change.cpp @@ -629,6 +629,7 @@ const mprinterr("Error: Data set '%s' is not scalar 1D.\n", ds->legend()); return 1; } + mprintf("\tUsing data from '%s' for masses.\n", ds->legend()); if (ds->Size() != (unsigned int)atomsToChange.Nselected()) { mprinterr("Error: %i atoms to change mass of, but set '%s' has %zu elements.\n", atomsToChange.Nselected(), ds->Size()); From 5dcdaced36ecfe9d17c3d1670d2110c5dba0ee3f Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Wed, 23 Aug 2023 09:33:33 -0400 Subject: [PATCH 06/10] Add ability to change charge as well --- src/Exec_Change.cpp | 63 ++++++++++++++++++++++++++++++++------------- src/Exec_Change.h | 2 +- 2 files changed, 46 insertions(+), 19 deletions(-) diff --git a/src/Exec_Change.cpp b/src/Exec_Change.cpp index 6bf45ea553..4aa06b21b4 100644 --- a/src/Exec_Change.cpp +++ b/src/Exec_Change.cpp @@ -18,6 +18,8 @@ void Exec_Change::Help() const "\t addbond [req ] |\n" "\t removebonds [] [out ]}\n" "\t bondparm [] {setrk|scalerk|setreq|scalereq} \n" + "\t mass [of ] {to |fromset }\n" + "\t charge [of ] {to |fromset }\n" " Change specified parts of topology or topology of a COORDS data set.\n", DataSetList::TopArgs); } @@ -28,7 +30,7 @@ Exec::RetType Exec_Change::Execute(CpptrajState& State, ArgList& argIn) // Change type enum ChangeType { UNKNOWN = 0, RESNAME, CHAINID, ORESNUMS, ICODES, ATOMNAME, ADDBOND, REMOVEBONDS, SPLITRES, BONDPARM, - MASS }; + MASS, CHARGE }; ChangeType type = UNKNOWN; if (argIn.hasKey("resname")) type = RESNAME; @@ -50,6 +52,8 @@ Exec::RetType Exec_Change::Execute(CpptrajState& State, ArgList& argIn) type = SPLITRES; else if (argIn.hasKey("mass")) type = MASS; + else if (argIn.hasKey("charge")) + type = CHARGE; if (type == UNKNOWN) { mprinterr("Error: No change type specified.\n"); return CpptrajState::ERR; @@ -81,7 +85,8 @@ Exec::RetType Exec_Change::Execute(CpptrajState& State, ArgList& argIn) case REMOVEBONDS : err = RemoveBonds(State, *parm, argIn); break; case BONDPARM : err = ChangeBondParameters(*parm, argIn); break; case SPLITRES : err = ChangeSplitRes(*parm, argIn); break; - case MASS : err = ChangeMass(*parm, argIn, State.DSL()); break; + case MASS : err = ChangeMassOrCharge(*parm, argIn, State.DSL(), 0); break; + case CHARGE : err = ChangeMassOrCharge(*parm, argIn, State.DSL(), 1); break; case UNKNOWN : err = 1; // sanity check } if (err != 0) return CpptrajState::ERR; @@ -598,10 +603,39 @@ int Exec_Change::ChangeBondParameters(Topology& topIn, ArgList& argIn) const { return 0; } -/** Change mass in topology */ -int Exec_Change::ChangeMass(Topology& topIn, ArgList& argIn, DataSetList const& DSL) +/** Function to change specific value in topology. */ +static inline void changeTopVal(Topology& topIn, int atnum, int typeIn, double newVal, + const char** desc) +{ + Atom& currentAtom = topIn.SetAtom(atnum); + double oldVal; + switch (typeIn) { + case 0 : + oldVal = currentAtom.Mass(); + currentAtom.SetMass( newVal ); + break; + case 1 : + oldVal = currentAtom.Charge(); + currentAtom.SetCharge( newVal ); break; + } + mprintf("\tChanging %s of atom '%s' from %g to %g\n", desc[typeIn], + topIn.AtomMaskName(atnum).c_str(), oldVal, newVal); +} + +/** Change mass/charge in topology. + * \param typeIn: 0=mass, 1=charge + */ +int Exec_Change::ChangeMassOrCharge(Topology& topIn, ArgList& argIn, + DataSetList const& DSL, int typeIn) const { + // sanity check + if (typeIn > 1 || typeIn < 0) { + mprinterr("Internal Error: typeIn is not 0 or 1.\n"); + return 1; + } + static const char* desc[] = { "mass", "charge" }; + std::string maskExpression = argIn.GetStringKey("of"); AtomMask atomsToChange; if (atomsToChange.SetMaskString( maskExpression )) { @@ -629,31 +663,24 @@ const mprinterr("Error: Data set '%s' is not scalar 1D.\n", ds->legend()); return 1; } - mprintf("\tUsing data from '%s' for masses.\n", ds->legend()); + mprintf("\tUsing data from '%s' for %s.\n", ds->legend(), desc[typeIn]); if (ds->Size() != (unsigned int)atomsToChange.Nselected()) { - mprinterr("Error: %i atoms to change mass of, but set '%s' has %zu elements.\n", - atomsToChange.Nselected(), ds->Size()); + mprinterr("Error: %i atoms to change %s of, but set '%s' has %zu elements.\n", + atomsToChange.Nselected(), desc[typeIn], ds->Size()); return 1; } DataSet_1D const& dset = static_cast( *ds ); for (int idx = 0; idx != atomsToChange.Nselected(); idx++) { - Atom& currentAtom = topIn.SetAtom( atomsToChange[idx] ); - mprintf("\tChanging mass of atom '%s' from %g to %g\n", - topIn.AtomMaskName(atomsToChange[idx]).c_str(), - currentAtom.Mass(), dset.Dval(idx)); - currentAtom.SetMass( dset.Dval(idx) ); + changeTopVal(topIn, atomsToChange[idx], typeIn, dset.Dval(idx), desc); } } else { if (!argIn.Contains("to")) { - mprinterr("Error: Expected either 'fromset' or 'to' for 'change mass'.\n"); + mprinterr("Error: Expected either 'fromset' or 'to' for 'change %s'.\n", desc[typeIn]); return 1; } - double newMass = argIn.getKeyDouble("to", 0.0); + double newVal = argIn.getKeyDouble("to", 0.0); for (AtomMask::const_iterator at = atomsToChange.begin(); at != atomsToChange.end(); ++at) { - Atom& currentAtom = topIn.SetAtom( *at ); - mprintf("\tChanging mass of atom '%s' from %g to %g\n", topIn.AtomMaskName(*at).c_str(), - currentAtom.Mass(), newMass); - currentAtom.SetMass( newMass ); + changeTopVal(topIn, *at, typeIn, newVal, desc); } } diff --git a/src/Exec_Change.h b/src/Exec_Change.h index bf847ee38f..7ab54ba1bc 100644 --- a/src/Exec_Change.h +++ b/src/Exec_Change.h @@ -21,6 +21,6 @@ class Exec_Change : public Exec { int AddBond(Topology&, ArgList&) const; int RemoveBonds(CpptrajState&, Topology&, ArgList&) const; int ChangeBondParameters(Topology&, ArgList&) const; - int ChangeMass(Topology&, ArgList&, DataSetList const&) const; + int ChangeMassOrCharge(Topology&, ArgList&, DataSetList const&, int) const; }; #endif From dec71fe4aedcf3fe7646bb90313804909d158125 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Wed, 23 Aug 2023 09:39:28 -0400 Subject: [PATCH 07/10] Fix help text. Add change mass|charge to manual. --- doc/cpptraj.lyx | 44 +++++++++++++++++++++++++++++++++++++++++++- src/Exec_Change.cpp | 4 ++-- 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/doc/cpptraj.lyx b/doc/cpptraj.lyx index 6641ba7a18..6c06584d01 100644 --- a/doc/cpptraj.lyx +++ b/doc/cpptraj.lyx @@ -13743,7 +13743,14 @@ change [parm | parmindex <#> | <#> | \begin_layout LyX-Code bondparm [] {setrk|scalerk|setreq|scalereq} - } +\end_layout + +\begin_layout LyX-Code + {mass|charge} [of ] {to |fromset } +\end_layout + +\begin_layout LyX-Code + } \end_layout \begin_deeper @@ -14033,6 +14040,41 @@ setreq Set bond equilibrium lengths to . scalereq Scale bond equilibirum lengths by . \end_layout +\end_deeper +\begin_layout Description +mass|charge Change mass or charge in specified topology. +\end_layout + +\begin_deeper +\begin_layout Description +of +\begin_inset space ~ +\end_inset + + Atoms to change mass/charge of. +\end_layout + +\begin_layout Description +to +\begin_inset space ~ +\end_inset + + Value to change mass/charge to. +\end_layout + +\begin_layout Description +fromset +\begin_inset space ~ +\end_inset + + Use values in for mass/charge; must have the same number + of values as atoms selected by . +\end_layout + \end_deeper \end_deeper \begin_layout Standard diff --git a/src/Exec_Change.cpp b/src/Exec_Change.cpp index 4aa06b21b4..c87d3b8a7d 100644 --- a/src/Exec_Change.cpp +++ b/src/Exec_Change.cpp @@ -18,8 +18,8 @@ void Exec_Change::Help() const "\t addbond [req ] |\n" "\t removebonds [] [out ]}\n" "\t bondparm [] {setrk|scalerk|setreq|scalereq} \n" - "\t mass [of ] {to |fromset }\n" - "\t charge [of ] {to |fromset }\n" + "\t {mass|charge} [of ] {to |fromset }\n" + "\t}\n" " Change specified parts of topology or topology of a COORDS data set.\n", DataSetList::TopArgs); } From d2b306b3ee3653c72dc747f10d9e8964fe8fa268 Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Wed, 23 Aug 2023 09:39:50 -0400 Subject: [PATCH 08/10] 6.20.4. Revision bump for change mass|charge --- src/Version.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Version.h b/src/Version.h index 5cac8ee66b..da68c718d0 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.20.3" +#define CPPTRAJ_INTERNAL_VERSION "V6.20.4" /// PYTRAJ relies on this #define CPPTRAJ_VERSION_STRING CPPTRAJ_INTERNAL_VERSION #endif From 39fd47be1d1c604bc0f6d386c54ddbc828dda7fd Mon Sep 17 00:00:00 2001 From: "Daniel R. Roe" Date: Wed, 23 Aug 2023 10:31:40 -0400 Subject: [PATCH 09/10] Protect test in parallel --- test/Test_Change/RunTest.sh | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/test/Test_Change/RunTest.sh b/test/Test_Change/RunTest.sh index ec5cf1e693..a09bbee718 100755 --- a/test/Test_Change/RunTest.sh +++ b/test/Test_Change/RunTest.sh @@ -64,7 +64,9 @@ EOF fi UNITNAME='Change mass from data set test' -cat > change.in < change.in < Date: Wed, 23 Aug 2023 10:32:38 -0400 Subject: [PATCH 10/10] Fix printf format --- src/Exec_Change.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Exec_Change.cpp b/src/Exec_Change.cpp index c87d3b8a7d..f86e324082 100644 --- a/src/Exec_Change.cpp +++ b/src/Exec_Change.cpp @@ -666,7 +666,7 @@ const mprintf("\tUsing data from '%s' for %s.\n", ds->legend(), desc[typeIn]); if (ds->Size() != (unsigned int)atomsToChange.Nselected()) { mprinterr("Error: %i atoms to change %s of, but set '%s' has %zu elements.\n", - atomsToChange.Nselected(), desc[typeIn], ds->Size()); + atomsToChange.Nselected(), desc[typeIn], ds->legend(), ds->Size()); return 1; } DataSet_1D const& dset = static_cast( *ds );