diff --git a/src/tools/PDB.cpp b/src/tools/PDB.cpp
index 63861ae1435c66c38201d74ce3b3324cca21f2a5..bfa79c4054fc4e7a924dd9b448d3898026a58278 100644
--- a/src/tools/PDB.cpp
+++ b/src/tools/PDB.cpp
@@ -255,6 +255,17 @@ std::vector<AtomNumber> PDB::getAtomsInResidue(const unsigned& resnum,const std:
   return tmp;
 }
 
+std::vector<AtomNumber> PDB::getAtomsInChain(const std::string& chainid)const {
+  std::vector<AtomNumber> tmp;
+  for(unsigned i=0;i<size();++i){
+     if( chainid=="*" || chain[i]==chainid ) tmp.push_back(numbers[i]);
+  }
+  if(tmp.size()==0) {
+    plumed_merror("Cannot find atoms from chain " + chainid  );
+  }
+  return tmp;
+}
+
 std::string PDB::getChainID(const unsigned& resnumber) const {
   for(unsigned i=0;i<size();++i){
      if(resnumber==residue[i]) return chain[i];
diff --git a/src/tools/PDB.h b/src/tools/PDB.h
index 93080df3e8efb0fe58b99a71b1fea7237d041e24..f44de3480b123253a95b7f668a12d06bd9122052 100644
--- a/src/tools/PDB.h
+++ b/src/tools/PDB.h
@@ -100,6 +100,8 @@ public:
   AtomNumber getNamedAtomFromResidueAndChain( const std::string& aname, const unsigned& resnum, const std::string& chain ) const;
 /// Access to the atoms of a residue 
   std::vector<AtomNumber> getAtomsInResidue(const unsigned& resnum,const std::string& chainid)const;
+/// Access to the atoms of a chain 
+  std::vector<AtomNumber> getAtomsInChain(const std::string& chainid)const;
 /// Get the extents of the blocks containing the atoms
   const std::vector<unsigned> & getAtomBlockEnds() const ;
 /// Get the number of blocks of atoms in the pdb