/** Based on the given atom mask expression determine what molecules are * selected by the mask. * \return A list of atom pairs that mark the beginning and end of each * selected molecule. */ Action_AutoImage::pairList Action_AutoImage::SetupAtomRanges( Topology const& currentParm, std::string const& maskexpr ) { pairList imageList; CharMask Mask1( maskexpr.c_str() ); if (currentParm.SetupCharMask( Mask1 )) return imageList; if (Mask1.None()) return imageList; for (Topology::mol_iterator mol = currentParm.MolStart(); mol != currentParm.MolEnd(); mol++) { int firstAtom = mol->BeginAtom(); int lastAtom = mol->EndAtom(); // Check that each atom in the range is in Mask1 bool rangeIsValid = true; for (int atom = firstAtom; atom < lastAtom; ++atom) { if (!Mask1.AtomInCharMask(atom)) { rangeIsValid = false; break; } } if (rangeIsValid) { imageList.push_back( firstAtom ); imageList.push_back( lastAtom ); } } mprintf("\tMask [%s] corresponds to %zu molecules\n", Mask1.MaskString(), imageList.size()/2); return imageList; }
/** An atom pair list consists of 2 values for each entry, a beginning * index and ending index. For molecules and residues this is the first * and just beyond the last atom; for atoms it is just the atom itself * twice. */ Image::PairType Image::CreatePairList(Topology const& Parm, Mode modeIn, std::string const& maskExpression) { PairType atomPairs; // Set up mask based on desired imaging mode. if ( modeIn == BYMOL || modeIn == BYRES ) { CharMask cmask( maskExpression ); if ( Parm.SetupCharMask( cmask ) ) return atomPairs; cmask.MaskInfo(); if (cmask.None()) return atomPairs; // Set up atom range for each entity to be imaged. if (modeIn == BYMOL) { atomPairs.reserve( Parm.Nmol()*2 ); for (Topology::mol_iterator mol = Parm.MolStart(); mol != Parm.MolEnd(); ++mol) CheckRange( atomPairs, cmask, mol->BeginAtom(), mol->EndAtom()); } else { // BYRES atomPairs.reserve( Parm.Nres()*2 ); for (Topology::res_iterator residue = Parm.ResStart(); residue != Parm.ResEnd(); ++residue) CheckRange( atomPairs, cmask, residue->FirstAtom(), residue->LastAtom() ); } } else { // BYATOM AtomMask imask( maskExpression ); if ( Parm.SetupIntegerMask( imask ) ) return atomPairs; imask.MaskInfo(); if (imask.None()) return atomPairs; atomPairs.reserve( Parm.Natom()*2 ); for (AtomMask::const_iterator atom = imask.begin(); atom != imask.end(); ++atom) { atomPairs.push_back( *atom ); atomPairs.push_back( (*atom)+1 ); } } // mprintf("\tNumber of %ss to be imaged is %zu based on mask '%s'\n", // ModeString[modeIn], atomPairs.size()/2, maskIn.MaskString()); return atomPairs; }