Skip to content

Commit

Permalink
Add ability to change names in 'atommap' command (#1060)
Browse files Browse the repository at this point in the history
* Add changenames keyword to change atom names in target topology during
atom mapping.

* Add test for changenames

* Update atommap help

* Update manual entry

* 6.22.2. Revision bump for atommap 'changenames' keyword.

* Protect in parallel

* Use setup-python v5

* Try using python 3.10 to get CI working

* Forgot to update the YML environment too
  • Loading branch information
drroe authored Dec 13, 2023
1 parent dd503b2 commit a7b1e03
Show file tree
Hide file tree
Showing 10 changed files with 177 additions and 14 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/merge-gate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,10 @@ jobs:
sudo apt-get install clang
sudo apt-get install cmake-data cmake
- uses: actions/checkout@v3
- name: Set up Python 3.8
uses: actions/setup-python@v4
- name: Set up Python 3.10
uses: actions/setup-python@v5
with:
python-version: '3.8'
python-version: '3.10'
- name: Add conda to system path
run: |
# $CONDA is an environment variable pointing to the root of the miniconda directory
Expand Down
2 changes: 1 addition & 1 deletion devtools/ci/environment.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
channels:
- conda-forge
dependencies:
- python=3.8
- python=3.10
- pyflakes
- numpy
- cython
Expand Down
9 changes: 9 additions & 0 deletions doc/cpptraj.lyx
Original file line number Diff line number Diff line change
Expand Up @@ -23367,6 +23367,10 @@ atommap

\end_layout

\begin_layout LyX-Code
[changenames]
\end_layout

\begin_deeper
\begin_layout Description
<target> Reference structure whose atoms will be remapped.
Expand Down Expand Up @@ -23427,6 +23431,11 @@ rmsout
\end_layout

\end_deeper
\begin_layout Description
changenames If specified, change names of mapped atoms in <target> to match
those in <reference>.
\end_layout

\end_deeper
\begin_layout Standard
Attempt to map the atoms of <target> to those of <reference> based on structural
Expand Down
31 changes: 24 additions & 7 deletions src/Action_AtomMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,18 @@ Action_AtomMap::Action_AtomMap() :
mode_(ALL),
maponly_(false),
rmsfit_(false),
renameAtoms_(false),
rmsdata_(0)
{}

void Action_AtomMap::Help() const {
mprintf("\t<target> <reference> [mapout <filename>] [maponly]\n"
"\t[rmsfit [ rmsout <rmsout> ]] [mode {all | byres}]\n"
"\t[changenames]\n"
" Attempt to create a map from atoms in <target> to atoms in <reference> solely\n"
" based on how they are bonded; remap <target> so it matches <reference>.\n"
" If 'rmsfit' is specified, calculate the RMSD of remapped target to reference.\n"
" If 'changenames' is specified change target atom names to match reference.\n"
" Modes: 'all' : try to map all atoms at once (default).\n"
" 'byres' : map residue by residue (assumes 1 to 1 residue correspondence).\n");
}
Expand All @@ -48,6 +51,7 @@ Action::RetType Action_AtomMap::Init(ArgList& actionArgs, ActionInit& init, int
# endif
maponly_ = actionArgs.hasKey("maponly");
rmsfit_ = actionArgs.hasKey("rmsfit");
renameAtoms_ = actionArgs.hasKey("changenames");
std::string modestring = actionArgs.GetStringKey("mode");
if (!modestring.empty()) {
if (modestring == "all") mode_ = ALL;
Expand Down Expand Up @@ -92,14 +96,18 @@ Action::RetType Action_AtomMap::Init(ArgList& actionArgs, ActionInit& init, int
mprintf("\tMap will only be written, not used to remap input trajectories.\n");
else
mprintf("\tAtoms in input trajectories matching target will be remapped.\n");
if (!maponly_ && rmsfit_) {
mprintf("\tWill RMS-fit mapped atoms in tgt to reference.\n");
if (rmsout != 0) {
rmsdata_ = init.DSL().AddSet(DataSet::DOUBLE, actionArgs.GetStringNext(), "RMSD");
if (rmsdata_==0) return Action::ERR;
rmsout->AddDataSet(rmsdata_);
mprintf("\tRMSDs will be written to '%s'\n", rmsout->DataFilename().full());
if (!maponly_) {
if (rmsfit_) {
mprintf("\tWill RMS-fit mapped atoms in tgt to reference.\n");
if (rmsout != 0) {
rmsdata_ = init.DSL().AddSet(DataSet::DOUBLE, actionArgs.GetStringNext(), "RMSD");
if (rmsdata_==0) return Action::ERR;
rmsout->AddDataSet(rmsdata_);
mprintf("\tRMSDs will be written to '%s'\n", rmsout->DataFilename().full());
}
}
if (renameAtoms_)
mprintf("\tTarget atom names will be renamed using reference atom names.\n");
}
switch (mode_) {
case BY_RES:
Expand Down Expand Up @@ -206,6 +214,15 @@ Action::RetType Action_AtomMap::Init(ArgList& actionArgs, ActionInit& init, int
newFrame_->SetupFrameM( TgtFrame_->Top().Atoms() );
// Set up new Parm
newParm_ = TgtFrame_->Top().ModifyByMap(AMap_);
if (renameAtoms_) {
// newParm_ is already in the correct order
for (int refatom = 0; refatom != (int)AMap_.size(); ++refatom) {
if (AMap_[refatom] != -1) {
//mprintf("DEBUG: ref %i name %s becomes tgt %i\n", refatom+1, *(RefFrame_->Top()[refatom].Name()), targetatom+1);
(*newParm_).SetAtom(refatom).SetName( RefFrame_->Top()[refatom].Name() );
}
}
}
}

return Action::OK;
Expand Down
1 change: 1 addition & 0 deletions src/Action_AtomMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class Action_AtomMap : public Action {
Frame rmsRefFrame_; ///< Ref frame for calculating RMS of remapped target to ref
Frame rmsTgtFrame_; ///< Tgt frame for calculating RMS of remapped target to ref
bool rmsfit_; ///< If true, attempt to RMS-fit remapped target to ref
bool renameAtoms_; ///< If true, rename target atoms to match reference
DataSet* rmsdata_; ///< RMS of remapped target to ref.
};
#endif
2 changes: 1 addition & 1 deletion src/Version.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* Whenever a number that precedes <revision> is incremented, all subsequent
* numbers should be reset to 0.
*/
#define CPPTRAJ_INTERNAL_VERSION "V6.22.1"
#define CPPTRAJ_INTERNAL_VERSION "V6.22.2"
/// PYTRAJ relies on this
#define CPPTRAJ_VERSION_STRING CPPTRAJ_INTERNAL_VERSION
#endif
48 changes: 48 additions & 0 deletions test/Test_AtomMap/ADD.names.mol2
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
@<TRIPOS>MOLECULE
ADD
18 19 1 0 0
SMALL
resp


@<TRIPOS>ATOM
1 C1 -3.0530 0.5460 0.0060 CT 1 ADD 0.063213
2 H1 -3.1040 1.2390 -0.8210 H1 1 ADD 0.047610
3 N1 -1.7830 -0.1470 -0.0030 N* 1 ADD -0.156619
4 C2 -1.5590 -1.5030 0.0010 CK 1 ADD 0.121145
5 H2 -2.3800 -2.1940 0.0030 H5 1 ADD 0.163537
6 N2 -0.3010 -1.8360 -0.0000 NB 1 ADD -0.546770
7 C3 0.3630 -0.6210 -0.0050 CB 1 ADD -0.088583
8 C4 1.7210 -0.2690 -0.0050 CA 1 ADD 0.819921
9 N3 2.7060 -1.1900 -0.0320 N2 1 ADD -0.958412
10 H3 3.6400 -0.8830 0.1180 H 1 ADD 0.419226
11 H4 2.4860 -2.1470 0.1200 H 1 ADD 0.419226
12 N4 2.0450 1.0240 0.0040 NC 1 ADD -0.822741
13 C5 1.0670 1.9280 0.0020 CQ 1 ADD 0.619667
14 H5 1.3920 2.9540 0.0070 H5 1 ADD 0.056434
15 N5 -0.2370 1.7300 -0.0020 NC 1 ADD -0.791023
16 C6 -0.5410 0.4290 -0.0040 CB 1 ADD 0.538950
17 H6 -3.8480 -0.1810 -0.0900 H1 1 ADD 0.047610
18 H7 -3.1820 1.0930 0.9310 H1 1 ADD 0.047610
@<TRIPOS>BOND
1 1 2 1
2 1 3 1
3 1 17 1
4 1 18 1
5 3 4 1
6 3 16 1
7 4 5 1
8 4 6 2
9 6 7 1
10 7 8 1
11 7 16 2
12 8 9 1
13 8 12 2
14 9 10 1
15 9 11 1
16 12 13 1
17 13 14 1
18 13 15 2
19 15 16 1
@<TRIPOS>SUBSTRUCTURE
1 ADD 1 TEMP 0 **** **** 0 ROOT
24 changes: 22 additions & 2 deletions test/Test_AtomMap/RunTest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# Clean
CleanFiles atommap.in initial.mol2 atommap.dat reordered.pdb reordered.mol2 \
fit.mol2 rmsd.dat map.chm_to_amb.dat mapped.pdb.? rmsout.dat \
map.byres.chm_to_amb.dat
map.byres.chm_to_amb.dat map.Base.dat remap.ADD.mol2

TESTNAME='Atom map tests'
Requires maxthreads 3
Expand Down Expand Up @@ -78,7 +78,6 @@ EOF
RunCpptraj "Atom map charmm->amber atom order"
DoTest map.chm_to_amb.dat.save map.chm_to_amb.dat

# Test 4
cat > atommap.in <<EOF
parm cg-amb.topo
reference cg-amb.crds
Expand All @@ -89,6 +88,27 @@ EOF
RunCpptraj "Atom map charmm->amber atom order, by residue"
DoTest map.chm_to_amb.dat.save map.byres.chm_to_amb.dat
fi

# Test 4
UNITNAME='Atom map with renaming test'
CheckFor maxthreads 1
if [ $? -eq 0 ] ; then
cat > atommap.in <<EOF
for FILE in template-base-adenine.pdb,ADD.names.mol2 NAME in Base0,Base1
parm \$FILE
reference \$FILE [\$NAME] parm \$FILE
done
atommap [Base1] [Base0] mapout map.Base.dat changenames
trajin ADD.names.mol2 parm ADD.names.mol2
trajout remap.ADD.mol2 parm ADD.names.mol2
run
EOF
RunCpptraj "$UNITNAME"
DoTest remap.ADD.mol2.save remap.ADD.mol2
fi

EndTest

exit 0
48 changes: 48 additions & 0 deletions test/Test_AtomMap/remap.ADD.mol2.save
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
@<TRIPOS>MOLECULE
Cpptraj Generated mol2 file.
18 19 1 0 0
SMALL
USER_CHARGES


@<TRIPOS>ATOM
1 C1' -3.0530 0.5460 0.0060 CT 1 ADD 0.063213
2 1H1' -3.1040 1.2390 -0.8210 H1 1 ADD 0.047610
3 2H1' -3.8480 -0.1810 -0.0900 H1 1 ADD 0.047610
4 3H1' -3.1820 1.0930 0.9310 H1 1 ADD 0.047610
5 N9 -1.7830 -0.1470 -0.0030 N* 1 ADD -0.156619
6 C8 -1.5590 -1.5030 0.0010 CK 1 ADD 0.121145
7 H8 -2.3800 -2.1940 0.0030 H5 1 ADD 0.163537
8 N7 -0.3010 -1.8360 -0.0000 NB 1 ADD -0.546770
9 C5 0.3630 -0.6210 -0.0050 CB 1 ADD -0.088583
10 C6 1.7210 -0.2690 -0.0050 CA 1 ADD 0.819921
11 N6 2.7060 -1.1900 -0.0320 N2 1 ADD -0.958412
12 H61 3.6400 -0.8830 0.1180 H 1 ADD 0.419226
13 H62 2.4860 -2.1470 0.1200 H 1 ADD 0.419226
14 N1 2.0450 1.0240 0.0040 NC 1 ADD -0.822741
15 C2 1.0670 1.9280 0.0020 CQ 1 ADD 0.619667
16 H2 1.3920 2.9540 0.0070 H5 1 ADD 0.056434
17 N3 -0.2370 1.7300 -0.0020 NC 1 ADD -0.791023
18 C4 -0.5410 0.4290 -0.0040 CB 1 ADD 0.538950
@<TRIPOS>BOND
1 1 5 1
2 5 6 1
3 5 18 1
4 6 8 1
5 8 9 1
6 9 10 1
7 9 18 1
8 10 11 1
9 10 14 1
10 14 15 1
11 15 17 1
12 17 18 1
13 1 2 1
14 1 3 1
15 1 4 1
16 6 7 1
17 11 12 1
18 11 13 1
19 15 16 1
@<TRIPOS>SUBSTRUCTURE
1 ADD 1 **** 0 **** ****
20 changes: 20 additions & 0 deletions test/Test_AtomMap/template-base-adenine.pdb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
ATOM 1 C1' DAA 1 4.559 1.151 3.778 1.00 0.00 C
ATOM 2 1H1' DAA 1 5.072 1.095 4.737 1.00 0.00 H
ATOM 3 2H1' DAA 1 5.108 1.778 3.076 1.00 0.00 H
ATOM 4 3H1' DAA 1 3.547 1.538 3.897 1.00 0.00 H
ATOM 5 N9 DAA 1 4.539 -0.297 3.316 1.00 0.00 N
ATOM 6 C8 DAA 1 4.337 -0.846 2.077 1.00 0.00 C
ATOM 7 H8 DAA 1 4.152 -0.207 1.226 1.00 0.00 H
ATOM 8 N7 DAA 1 4.453 -2.141 2.049 1.00 0.00 N
ATOM 9 C5 DAA 1 4.754 -2.480 3.363 1.00 0.00 C
ATOM 10 C6 DAA 1 4.998 -3.708 3.989 1.00 0.00 C
ATOM 11 N6 DAA 1 4.977 -4.883 3.346 1.00 0.00 N
ATOM 12 H61 DAA 1 5.161 -5.739 3.851 1.00 0.00 H
ATOM 13 H62 DAA 1 4.777 -4.914 2.356 1.00 0.00 H
ATOM 14 N1 DAA 1 5.265 -3.689 5.302 1.00 0.00 N
ATOM 15 C2 DAA 1 5.285 -2.520 5.935 1.00 0.00 C
ATOM 16 H2 DAA 1 5.498 -2.482 6.993 1.00 0.00 H
ATOM 17 N3 DAA 1 5.073 -1.309 5.456 1.00 0.00 N
ATOM 18 C4 DAA 1 4.806 -1.356 4.133 1.00 0.00 C
TER
END

0 comments on commit a7b1e03

Please sign in to comment.