"molindex" and "atomtype" keywords are now covered by separate tests.
Also updated one test to use the "z" keyword to have that covered.
Added a comment in sm_simple.cpp about unreachable code that is not
currently covered by tests.
Part of #651.
Change-Id: Id9ac9ea8e7d144214537265d9ed89335684934f1
}
}
}
+ if (bFreeNames && atoms->atomtype != NULL)
+ {
+ for (i = 0; i < atoms->nr; i++)
+ {
+ if (atoms->atomtype[i] != NULL)
+ {
+ sfree(*atoms->atomtype[i]);
+ *atoms->atomtype[i] = NULL;
+ }
+ }
+ }
+ if (bFreeNames && atoms->atomtypeB != NULL)
+ {
+ for (i = 0; i < atoms->nr; i++)
+ {
+ if (atoms->atomtypeB[i] != NULL)
+ {
+ sfree(*atoms->atomtypeB[i]);
+ *atoms->atomtypeB[i] = NULL;
+ }
+ }
+ }
sfree(atoms->atomname);
- /* Do we need to free atomtype and atomtypeB as well ? */
+ sfree(atoms->atomtype);
+ sfree(atoms->atomtypeB);
sfree(atoms->resinfo);
sfree(atoms->atom);
sfree(atoms->pdbinfo);
- atoms->nr = 0;
- atoms->nres = 0;
- atoms->atomname = NULL;
- atoms->resinfo = NULL;
- atoms->atom = NULL;
- atoms->pdbinfo = NULL;
+ atoms->nr = 0;
+ atoms->nres = 0;
+ atoms->atomname = NULL;
+ atoms->atomtype = NULL;
+ atoms->atomtypeB = NULL;
+ atoms->resinfo = NULL;
+ atoms->atom = NULL;
+ atoms->pdbinfo = NULL;
}
real max_cutoff(real cutoff1, real cutoff2)
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2009,2010,2011,2012, by the GROMACS development team, led by
+ * Copyright (c) 2009,2010,2011,2012,2013, by the GROMACS development team, led by
* David van der Spoel, Berk Hess, Erik Lindahl, and including many
* others, as listed in the AUTHORS file in the top-level source
* directory and at http://www.gromacs.org.
}
else
{
+ // TODO: This loop is never reached in the current code.
+ // It would be useful to change the code such that it is, mostly for
+ // memory efficiency reasons.
for (i = 0; i < g->isize; ++i)
{
out[i] = fr->x[g->index[i]][d];
--- /dev/null
+<?xml version="1.0"?>
+<?xml-stylesheet type="text/xsl" href="referencedata.xsl"?>
+<ReferenceData>
+ <ParsedSelections Name="Parsed">
+ <ParsedSelection Name="Selection1">
+ <String Name="Input">atomtype CA</String>
+ <String Name="Name">atomtype CA</String>
+ <String Name="Text">atomtype CA</String>
+ <Bool Name="Dynamic">false</Bool>
+ </ParsedSelection>
+ </ParsedSelections>
+ <CompiledSelections Name="Compiled">
+ <Selection Name="Selection1">
+ <Sequence Name="Atoms">
+ <Int Name="Length">5</Int>
+ <Int>0</Int>
+ <Int>3</Int>
+ <Int>6</Int>
+ <Int>9</Int>
+ <Int>12</Int>
+ </Sequence>
+ </Selection>
+ </CompiledSelections>
+</ReferenceData>
<Bool Name="Dynamic">true</Bool>
</ParsedSelection>
<ParsedSelection Name="Selection2">
- <String Name="Input">(resnr 1 3 5 or x > 10) and same residue as (atomnr 3 5 13 or y > 5)</String>
- <String Name="Name">(resnr 1 3 5 or x > 10) and same residue as (atomnr 3 5 13 or y > 5)</String>
- <String Name="Text">(resnr 1 3 5 or x > 10) and same residue as (atomnr 3 5 13 or y > 5)</String>
+ <String Name="Input">(resnr 1 3 5 or x > 10) and same residue as (atomnr 3 5 13 or z > 5)</String>
+ <String Name="Name">(resnr 1 3 5 or x > 10) and same residue as (atomnr 3 5 13 or z > 5)</String>
+ <String Name="Text">(resnr 1 3 5 or x > 10) and same residue as (atomnr 3 5 13 or z > 5)</String>
<Bool Name="Dynamic">true</Bool>
</ParsedSelection>
</ParsedSelections>
--- /dev/null
+<?xml version="1.0"?>
+<?xml-stylesheet type="text/xsl" href="referencedata.xsl"?>
+<ReferenceData>
+ <ParsedSelections Name="Parsed">
+ <ParsedSelection Name="Selection1">
+ <String Name="Input">molindex 1 4</String>
+ <String Name="Name">molindex 1 4</String>
+ <String Name="Text">molindex 1 4</String>
+ <Bool Name="Dynamic">false</Bool>
+ </ParsedSelection>
+ <ParsedSelection Name="Selection2">
+ <String Name="Input">molecule 2 3 5</String>
+ <String Name="Name">molecule 2 3 5</String>
+ <String Name="Text">molecule 2 3 5</String>
+ <Bool Name="Dynamic">false</Bool>
+ </ParsedSelection>
+ </ParsedSelections>
+ <CompiledSelections Name="Compiled">
+ <Selection Name="Selection1">
+ <Sequence Name="Atoms">
+ <Int Name="Length">6</Int>
+ <Int>0</Int>
+ <Int>1</Int>
+ <Int>2</Int>
+ <Int>9</Int>
+ <Int>10</Int>
+ <Int>11</Int>
+ </Sequence>
+ </Selection>
+ <Selection Name="Selection2">
+ <Sequence Name="Atoms">
+ <Int Name="Length">9</Int>
+ <Int>3</Int>
+ <Int>4</Int>
+ <Int>5</Int>
+ <Int>6</Int>
+ <Int>7</Int>
+ <Int>8</Int>
+ <Int>12</Int>
+ <Int>13</Int>
+ <Int>14</Int>
+ </Sequence>
+ </Selection>
+ </CompiledSelections>
+</ReferenceData>
ASSERT_NO_THROW_GMX(sc_.setTopology(NULL, natoms));
}
void loadTopology(const char *filename);
+ void setTopology();
- gmx::SelectionCollection sc_;
- gmx::SelectionList sel_;
- t_topology *top_;
- t_trxframe *frame_;
-
- private:
gmx::test::TopologyManager topManager_;
+ gmx::SelectionCollection sc_;
+ gmx::SelectionList sel_;
+ t_topology *top_;
+ t_trxframe *frame_;
};
int SelectionCollectionTest::s_debugLevel = 0;
SelectionCollectionTest::loadTopology(const char *filename)
{
topManager_.loadTopology(filename);
+ setTopology();
+}
+
+void
+SelectionCollectionTest::setTopology()
+{
top_ = topManager_.topology();
frame_ = topManager_.frame();
runTest("simple.pdb", selections);
}
-// TODO: Add test for "molindex"
+TEST_F(SelectionCollectionDataTest, HandlesMolIndex)
+{
+ static const char * const selections[] = {
+ "molindex 1 4",
+ "molecule 2 3 5"
+ };
+ ASSERT_NO_FATAL_FAILURE(runParser(selections));
+ ASSERT_NO_FATAL_FAILURE(loadTopology("simple.gro"));
+ topManager_.initUniformMolecules(3);
+ ASSERT_NO_FATAL_FAILURE(runCompiler());
+}
TEST_F(SelectionCollectionDataTest, HandlesAtomname)
{
runTest("simple.pdb", selections);
}
-// TODO: Add test for atomtype
+
+TEST_F(SelectionCollectionDataTest, HandlesAtomtype)
+{
+ static const char * const selections[] = {
+ "atomtype CA"
+ };
+ ASSERT_NO_FATAL_FAILURE(runParser(selections));
+ ASSERT_NO_FATAL_FAILURE(loadTopology("simple.gro"));
+ const char *const types[] = { "CA", "SA", "SB" };
+ topManager_.initAtomTypes(types);
+ ASSERT_NO_FATAL_FAILURE(runCompiler());
+}
TEST_F(SelectionCollectionDataTest, HandlesChain)
{
{
static const char * const selections[] = {
"same residue as (atomnr 3 5 13 or y > 5)",
- "(resnr 1 3 5 or x > 10) and same residue as (atomnr 3 5 13 or y > 5)"
+ "(resnr 1 3 5 or x > 10) and same residue as (atomnr 3 5 13 or z > 5)"
};
setFlags(TestFlags() | efTestEvaluation);
runTest("simple.gro", selections);
#include "gromacs/legacyheaders/smalloc.h"
#include "gromacs/legacyheaders/statutil.h"
+#include "gromacs/legacyheaders/string2.h"
#include "gromacs/legacyheaders/tpxio.h"
#include "gromacs/legacyheaders/typedefs.h"
#include "gromacs/legacyheaders/vec.h"
}
}
+void TopologyManager::initAtomTypes(int count, const char *const types[])
+{
+ GMX_RELEASE_ASSERT(top_ != NULL, "Topology not initialized");
+ atomtypes_.reserve(count);
+ for (int i = 0; i < count; ++i)
+ {
+ atomtypes_.push_back(strdup(types[i]));
+ }
+ snew(top_->atoms.atomtype, top_->atoms.nr);
+ for (int i = 0, j = 0; i < top_->atoms.nr; ++i, ++j)
+ {
+ if (j == count)
+ {
+ j = 0;
+ }
+ top_->atoms.atomtype[i] = &atomtypes_[j];
+ }
+}
+
void TopologyManager::initUniformResidues(int residueSize)
{
GMX_RELEASE_ASSERT(top_ != NULL, "Topology not initialized");
#ifndef GMX_SELECTION_TESTS_TOPUTILS_H
#define GMX_SELECTION_TESTS_TOPUTILS_H
+#include <vector>
+
#include "gromacs/legacyheaders/typedefs.h"
namespace gmx
void loadTopology(const char *filename);
void initAtoms(int count);
+ void initAtomTypes(int count, const char *const types[]);
+ template <int count>
+ void initAtomTypes(const char *const (&types)[count])
+ {
+ initAtomTypes(count, types);
+ }
void initUniformResidues(int residueSize);
void initUniformMolecules(int moleculeSize);
t_trxframe *frame() { return frame_; }
private:
- t_topology *top_;
- t_trxframe *frame_;
+ t_topology *top_;
+ t_trxframe *frame_;
+ std::vector<char *> atomtypes_;
};
} // namespace test