/** Like the strip action, closest will modify the current parm keeping info * for atoms in mask plus the closestWaters solvent molecules. Set up the * vector of MolDist objects, one for every solvent molecule in the original * parm file. Atom masks for each solvent molecule will be set up. */ Action_Closest::RetType Action_Closest::Setup(Topology const& topIn, CoordinateInfo const& cInfoIn) { // If there are no solvent molecules this action is not valid. if (topIn.Nsolvent()==0) { mprintf("Warning: Parm %s does not contain solvent.\n",topIn.c_str()); return Action_Closest::SKIP; } // If # solvent to keep >= solvent in this parm the action is not valid. if (closestWaters_ >= topIn.Nsolvent()) { mprintf("Warning: # solvent to keep (%i) >= # solvent molecules in '%s' (%i)\n", closestWaters_, topIn.c_str(), topIn.Nsolvent()); return Action_Closest::SKIP; } image_.SetupImaging( cInfoIn.TrajBox().Type() ); if (image_.ImagingEnabled()) mprintf("\tDistances will be imaged.\n"); else mprintf("\tImaging off.\n"); // LOOP OVER MOLECULES // 1: Check that all solvent molecules contain same # atoms. Solvent // molecules must be identical for the command to work properly; // the prmtop strip occurs only once so the solvent params become fixed. // 2: Set up a mask for all solvent molecules. SolventMols_.clear(); // NOTE: May not be necessary to init 'solvent' MolDist solvent; solvent.D = 0.0; solvent.mol = 0; SolventMols_.resize(topIn.Nsolvent(), solvent); std::vector<MolDist>::iterator mdist = SolventMols_.begin(); // 3: Set up the soluteMask for all non-solvent molecules. int molnum = 1; int nclosest = 0; int NsolventAtoms = -1; for (Topology::mol_iterator Mol = topIn.MolStart(); Mol != topIn.MolEnd(); ++Mol) { if ( Mol->IsSolvent() ) { // Solvent, check for same # of atoms. if (NsolventAtoms == -1) NsolventAtoms = Mol->NumAtoms(); else if ( NsolventAtoms != Mol->NumAtoms() ) { mprinterr("Error: Solvent molecules in '%s' are not of uniform size.\n" "Error: First solvent mol = %i atoms, solvent mol %i = %i atoms.\n", topIn.c_str(), NsolventAtoms, molnum, (*Mol).NumAtoms()); return Action_Closest::ERR; } // mol here is the output molecule number which is why it starts from 1. mdist->mol = molnum; // Solvent molecule mask mdist->mask.AddAtomRange( Mol->BeginAtom(), Mol->EndAtom() ); // Atoms in the solvent molecule to actually calculate distances to. if (firstAtom_) { mdist->solventAtoms.assign(1, Mol->BeginAtom() ); } else { mdist->solventAtoms.clear(); mdist->solventAtoms.reserve( Mol->NumAtoms() ); for (int svatom = Mol->BeginAtom(); svatom < Mol->EndAtom(); svatom++) mdist->solventAtoms.push_back( svatom ); } if (debug_ > 0) { mprintf("DEBUG:\tSet up mol %i:", mdist->mol); // DEBUG mdist->mask.PrintMaskAtoms("solvent"); // DEBUG mprintf("\n"); // DEBUG } ++mdist; } ++molnum; } // Setup distance atom mask // NOTE: Should ensure that no solvent atoms are selected! if ( topIn.SetupIntegerMask(distanceMask_) ) return Action_Closest::ERR; if (distanceMask_.None()) { mprintf("Warning: Distance mask '%s' contains no atoms.\n", distanceMask_.MaskString()); return Action_Closest::SKIP; } distanceMask_.MaskInfo(); // Check the total number of solvent atoms to be kept. NsolventAtoms *= closestWaters_; mprintf("\tKeeping %i solvent atoms.\n",NsolventAtoms); if (NsolventAtoms < 1) { mprintf("Warning: # of solvent atoms to be kept is < 1.\n"); return Action_Closest::SKIP; } NsolventMolecules_ = (int)SolventMols_.size(); return Action_Closest::OK; }
/** Each rank only sets up file that it will process. */ int TrajIOarray::SetupIOarray(ArgList& argIn, TrajFrameCounter& counter, CoordinateInfo& cInfo, Topology* trajParm, Parallel::Comm const& ensComm, Parallel::Comm const& trajComm) { // Sanity check if (!IOarray_.empty()) { mprinterr("Internal Error: SetupIOarray() has been called twice.\n"); return 1; } // Detect format FileName const& repFname = replica_filenames_[ensComm.Rank()]; TrajectoryFile::TrajFormatType repformat = TrajectoryFile::UNKNOWN_TRAJ; TrajectoryIO* replica0 = TrajectoryFile::DetectFormat( repFname, repformat ); if ( replica0 == 0 ) { mprinterr("Error: Could not set up replica file %s\n", repFname.full()); return 1; } mprintf("\tReading '%s' as %s\n", repFname.full(), TrajectoryFile::FormatString(repformat)); replica0->SetDebug( debug_ ); // Construct the IOarray_ with blanks for all except this rank. for (int member = 0; member != ensComm.Size(); member++) if (member == ensComm.Rank()) IOarray_.push_back( replica0 ); else IOarray_.push_back( 0 ); // Process format-specific read args. replica0->processReadArgs( argIn ); // Set up replica for reading and get # frames int nframes = replica0->setupTrajin( repFname, trajParm ); if (nframes == TrajectoryIO::TRAJIN_ERR) { mprinterr("Error: Could not set up %s for reading.\n", repFname.full()); return 1; } // Set coordinate info cInfo = replica0->CoordInfo(); int totalFrames = nframes; if (cInfo.ReplicaDimensions().Ndims() > 0) { // TODO put in common routine mprintf("\tReplica dimensions:\n"); for (int rd = 0; rd < cInfo.ReplicaDimensions().Ndims(); rd++) mprintf("\t\t%i: %s\n", rd+1, cInfo.ReplicaDimensions().Description(rd)); } // Check # frames in all files, use lowest. Parallel::World().AllReduce( &totalFrames, &nframes, 1, MPI_INT, MPI_MIN ); if (totalFrames != nframes) { rprintf("Warning: Replica '%s' frames (%i) is > # frames in shortest replica.\n", repFname.full(), nframes); mprintf("Warning: Setting total # of frames to read from replica ensemble to %i\n", totalFrames); } if (trajComm.Master()) { static const int iSize = 6; static const char* iTitle[iSize] = {"box", "velocity", "temperature", "time", "force", "replica dimensions"}; // Check coordinate info of all files 0 1 2 3 4 5 std::vector<int> Info( iSize * ensComm.Size() ); // box, vel, temp, time, force, nRepDims int rank_info[iSize]; rank_info[0] = (int)cInfo.TrajBox().Type(); rank_info[1] = (int)cInfo.HasVel(); rank_info[2] = (int)cInfo.HasTemp(); rank_info[3] = (int)cInfo.HasTime(); rank_info[4] = (int)cInfo.HasForce(); rank_info[5] = cInfo.ReplicaDimensions().Ndims(); ensComm.AllGather( rank_info, iSize, MPI_INT, &Info[0] ); // TODO Should mismatches be errors instead? for (int midx = 0; midx != iSize; midx++) { for (int ridx = midx + iSize; ridx < (int)Info.size(); ridx += iSize) { if (Info[midx] != Info[ridx]) { rprintf("Warning: Replica %i %s info does not match first replica.\n", ridx/iSize, iTitle[midx]); } } } } // TODO: Put code below into a common routine with serial version // Check how many frames will actually be read if (counter.CheckFrameArgs( totalFrames, argIn )) return 1; // SANITY CHECK if (IOarray_.size() != replica_filenames_.size()) { mprinterr("Error: Not all replica files were set up.\n"); return 1; } // Update ensemble size cInfo.SetEnsembleSize( (int)IOarray_.size() ); if (debug_ > 0) cInfo.PrintCoordInfo( repFname.full(), trajParm->c_str() ); return 0; }