Skip to content

Commit

Permalink
Add mass and charge keywords, add test
Browse files Browse the repository at this point in the history
  • Loading branch information
drroe committed Jul 12, 2024
1 parent 6f6f3b2 commit 79e18e3
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 2 deletions.
21 changes: 20 additions & 1 deletion src/Action_AddAtom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Action_AddAtom::~Action_AddAtom() {
// Action_AddAtom::Help()
void Action_AddAtom::Help() const {
mprintf("\taname <name> [elt <element>] [rname <res name>]\n"
"\t[xyz <X> <Y> <Z>]\n");
"\t[xyz <X> <Y> <Z>] [mass <mass>] [charge <charge>]\n");
mprintf("%s", ActionTopWriter::Keywords());
mprintf(" Add an atom to current topology/coordinates.\n");
}
Expand Down Expand Up @@ -45,6 +45,21 @@ Action::RetType Action_AddAtom::Init(ArgList& actionArgs, ActionInit& init, int
rname.assign("TMP");
residueName_ = NameType( rname );

bool has_mass = false;
double mass = 0;
if (actionArgs.Contains("mass")) {
has_mass = true;
mass = actionArgs.getKeyDouble("mass", 0);
}

bool has_charge = false;
double charge = 0;
if (actionArgs.Contains("charge")) {
has_charge = true;
charge = actionArgs.getKeyDouble("charge", 0);
}

// ----- Last arg to process -----
if (actionArgs.Contains("xyz")) {
ArgList xyzargs = actionArgs.GetNstringKey("xyz", 3);
if (xyzargs.Nargs() != 3) {
Expand All @@ -59,9 +74,13 @@ Action::RetType Action_AddAtom::Init(ArgList& actionArgs, ActionInit& init, int

// ----- No more args after here -----
newAtom_ = Atom(atomName, elt.c_str());
if (has_mass) newAtom_.SetMass( mass );
if (has_charge) newAtom_.SetCharge( charge );

mprintf(" ADDATOM: Adding atom named '%s', element %s, residue name '%s'\n",
*atomName, elt.c_str(), *residueName_);
if (has_mass) mprintf("\tAtom mass = %g\n", mass);
if (has_charge) mprintf("\tAtom charge = %g\n", charge);
mprintf("\tAtom will be placed at XYZ= %g %g %g\n", xyz_[0], xyz_[1], xyz_[2]);
topWriter_.PrintOptions();

Expand Down
12 changes: 11 additions & 1 deletion test/Test_AddAtom/RunTest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

. ../MasterTest.sh

CleanFiles addatom.in tz2.addatom.pdb tz2.mask.dat
CleanFiles addatom.in tz2.addatom.pdb tz2.mask.dat tz2.mg.mol2

TESTNAME='Add atom tests'

Expand All @@ -22,4 +22,14 @@ RunCpptraj "Add atom test"
DoTest tz2.addatom.pdb.save tz2.addatom.pdb
DoTest tz2.mask.dat.save tz2.mask.dat

cat > addatom.in <<EOF
parm ../tz2.parm7
trajin ../tz2.pdb 1 1
strip !:1
addatom aname MG rname MG mass 24.3 charge 2 xyz 3 4 5
trajout tz2.mg.mol2
EOF
RunCpptraj "Add atom test, MG"
DoTest tz2.mg.mol2.save tz2.mg.mol2

EndTest
38 changes: 38 additions & 0 deletions test/Test_AddAtom/tz2.mg.mol2.save
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
@<TRIPOS>MOLECULE
Cpptraj Generated mol2 file.
14 12 2 0 0
SMALL
USER_CHARGES


@<TRIPOS>ATOM
1 N -1.8890 9.1590 7.5690 N3 1 SER 0.184900
2 H1 -1.0370 8.6910 7.2960 H 1 SER 0.189800
3 H2 -1.9000 9.2980 8.5690 H 1 SER 0.189800
4 H3 -2.5380 8.4470 7.2650 H 1 SER 0.189800
5 CA -2.0640 10.5010 6.9930 CT 1 SER 0.056700
6 HA -3.1000 10.8240 7.1020 HP 1 SER 0.078200
7 CB -1.2300 11.5610 7.7070 CT 1 SER 0.259600
8 HB2 -1.6700 11.8110 8.6730 H1 1 SER 0.027300
9 HB3 -1.2480 12.5030 7.1590 H1 1 SER 0.027300
10 OG 0.1230 11.2160 7.9040 OH 1 SER -0.671400
11 HG 0.2740 11.7280 8.7010 HO 1 SER 0.423900
12 C -1.6130 10.4180 5.5420 C 1 SER 0.616300
13 O -2.4980 10.4330 4.6890 O 1 SER -0.572200
14 MG 3.0000 4.0000 5.0000 MG 2 MG 2.000000
@<TRIPOS>BOND
1 12 13 1
2 7 10 1
3 5 7 1
4 5 12 1
5 1 5 1
6 10 11 1
7 7 8 1
8 7 9 1
9 5 6 1
10 1 2 1
11 1 3 1
12 1 4 1
@<TRIPOS>SUBSTRUCTURE
1 SER 1 **** 0 **** ****
2 MG 14 **** 0 **** ****

0 comments on commit 79e18e3

Please sign in to comment.