/usr/include/gromacs/selection/selection.h is in libgromacs-dev 2018.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 | /*
* This file is part of the GROMACS molecular simulation package.
*
* Copyright (c) 2009,2010,2011,2012,2013,2014,2015,2016,2017, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
*
* GROMACS is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
*
* GROMACS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with GROMACS; if not, see
* http://www.gnu.org/licenses, or write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* If you want to redistribute modifications to GROMACS, please
* consider that scientific software is very special. Version
* control is crucial - bugs must be traceable. We will be happy to
* consider code for inclusion in the official distribution, but
* derived work must not be called official GROMACS. Details are found
* in the README & COPYING files - if they are missing, get the
* official version at http://www.gromacs.org.
*
* To help us fund GROMACS development, we humbly ask that you cite
* the research papers on the package. Check out http://www.gromacs.org.
*/
/*! \file
* \brief
* Declares gmx::Selection and supporting classes.
*
* \author Teemu Murtola <teemu.murtola@gmail.com>
* \inpublicapi
* \ingroup module_selection
*/
#ifndef GMX_SELECTION_SELECTION_H
#define GMX_SELECTION_SELECTION_H
#include <string>
#include <vector>
#include "gromacs/selection/position.h"
#include "gromacs/selection/selectionenums.h"
#include "gromacs/utility/arrayref.h"
#include "gromacs/utility/classhelpers.h"
#include "gromacs/utility/gmxassert.h"
struct gmx_mtop_t;
namespace gmx
{
class SelectionOptionStorage;
class SelectionTreeElement;
class AnalysisNeighborhoodPositions;
class Selection;
class SelectionPosition;
//! Container of selections used in public selection interfaces.
typedef std::vector<Selection> SelectionList;
namespace internal
{
/*! \internal
* \brief
* Internal data for a single selection.
*
* This class is internal to the selection module, but resides in a public
* header because of efficiency reasons: it allows frequently used access
* methods in \ref Selection to be inlined.
*
* Methods in this class do not throw unless otherwise specified.
*
* \ingroup module_selection
*/
class SelectionData
{
public:
/*! \brief
* Creates a new selection object.
*
* \param[in] elem Root of the evaluation tree for this selection.
* \param[in] selstr String that was parsed to produce this selection.
* \throws std::bad_alloc if out of memory.
*/
SelectionData(SelectionTreeElement *elem, const char *selstr);
~SelectionData();
//! Returns the name for this selection.
const char *name() const { return name_.c_str(); }
//! Returns the string that was parsed to produce this selection.
const char *selectionText() const { return selectionText_.c_str(); }
//! Returns true if the size of the selection (posCount()) is dynamic.
bool isDynamic() const { return bDynamic_; }
//! Returns the type of positions in the selection.
e_index_t type() const { return rawPositions_.m.type; }
//! Returns true if the selection only contains positions with a single atom each.
bool hasOnlyAtoms() const { return type() == INDEX_ATOM; }
//! Returns `true` if the atom indices in the selection are in ascending order.
bool hasSortedAtomIndices() const;
//! Number of positions in the selection.
int posCount() const { return rawPositions_.count(); }
//! Returns the root of the evaluation tree for this selection.
SelectionTreeElement &rootElement() { return rootElement_; }
//! Returns whether the covered fraction can change between frames.
bool isCoveredFractionDynamic() const { return bDynamicCoveredFraction_; }
//! Returns true if the given flag is set.
bool hasFlag(SelectionFlag flag) const { return flags_.test(flag); }
//! Sets the flags for this selection.
void setFlags(SelectionFlags flags) { flags_ = flags; }
//! \copydoc Selection::initCoveredFraction()
bool initCoveredFraction(e_coverfrac_t type);
/*! \brief
* Updates the name of the selection if missing.
*
* \throws std::bad_alloc if out of memory.
*
* If selections get their value from a group reference that cannot be
* resolved during parsing, the name is final only after group
* references have been resolved.
*
* This function is called by SelectionCollection::setIndexGroups().
*/
void refreshName();
/*! \brief
* Computes total masses and charges for all selection positions.
*
* \param[in] top Topology information.
* \throws std::bad_alloc if out of memory.
*
* For dynamic selections, the values need to be updated after each
* evaluation with refreshMassesAndCharges().
* This is done by SelectionEvaluator.
*
* This function is called by SelectionCompiler.
*
* Strong exception safety guarantee.
*/
void initializeMassesAndCharges(const gmx_mtop_t *top);
/*! \brief
* Updates masses and charges after dynamic selection has been
* evaluated.
*
* \param[in] top Topology information.
*
* Called by SelectionEvaluator.
*/
void refreshMassesAndCharges(const gmx_mtop_t *top);
/*! \brief
* Updates the covered fraction after a selection has been evaluated.
*
* Called by SelectionEvaluator.
*/
void updateCoveredFractionForFrame();
/*! \brief
* Computes average covered fraction after all frames have been evaluated.
*
* \param[in] nframes Number of frames that have been evaluated.
*
* \p nframes should be equal to the number of calls to
* updateCoveredFractionForFrame().
* Called by SelectionEvaluator::evaluateFinal().
*/
void computeAverageCoveredFraction(int nframes);
/*! \brief
* Restores position information to state it was in after compilation.
*
* \param[in] top Topology information.
*
* Depends on SelectionCompiler storing the original atoms in the
* \a rootElement_ object.
* Called by SelectionEvaluator::evaluateFinal().
*/
void restoreOriginalPositions(const gmx_mtop_t *top);
private:
//! Name of the selection.
std::string name_;
//! The actual selection string.
std::string selectionText_;
//! Low-level representation of selected positions.
gmx_ana_pos_t rawPositions_;
//! Total masses for the current positions.
std::vector<real> posMass_;
//! Total charges for the current positions.
std::vector<real> posCharge_;
SelectionFlags flags_;
//! Root of the selection evaluation tree.
SelectionTreeElement &rootElement_;
//! Type of the covered fraction.
e_coverfrac_t coveredFractionType_;
//! Covered fraction of the selection for the current frame.
real coveredFraction_;
//! The average covered fraction (over the trajectory).
real averageCoveredFraction_;
//! true if the value can change as a function of time.
bool bDynamic_;
//! true if the covered fraction depends on the frame.
bool bDynamicCoveredFraction_;
/*! \brief
* Needed to wrap access to information.
*/
friend class gmx::Selection;
/*! \brief
* Needed for proper access to position information.
*/
friend class gmx::SelectionPosition;
GMX_DISALLOW_COPY_AND_ASSIGN(SelectionData);
};
} // namespace internal
/*! \brief
* Provides access to a single selection.
*
* This class provides a public interface for accessing selection information.
* General information about the selection can be accessed with methods name(),
* selectionText(), isDynamic(), and type(). The first three can be accessed
* any time after the selection has been parsed, and type() can be accessed
* after the selection has been compiled.
*
* There are a few methods that can be used to change the behavior of the
* selection. setEvaluateVelocities() and setEvaluateForces() can be called
* before the selection is compiled to request evaluation of velocities and/or
* forces in addition to coordinates.
*
* Each selection is made of a set of positions. Each position has associated
* coordinates, and possibly velocities and forces if they have been requested
* and are available. It also has a set of atoms associated with it; typically
* the coordinates are the center-of-mass or center-of-geometry coordinates for
* that set of atoms. To access the number of positions in the selection, use
* posCount(). To access individual positions, use position().
* See SelectionPosition for details of how to use individual positions.
* setOriginalId() can be used to adjust the return value of
* SelectionPosition::mappedId(); see that method for details.
*
* It is also possible to access the list of atoms that make up all the
* positions directly: atomCount() returns the total number of atoms in the
* selection and atomIndices() an array of their indices.
* Similarly, it is possible to access the coordinates and other properties
* of the positions as continuous arrays through coordinates(), velocities(),
* forces(), masses(), charges(), refIds(), and mappedIds().
*
* Both positions and atoms can be accessed after the selection has been
* compiled. For dynamic selections, the return values of these methods change
* after each evaluation to reflect the situation for the current frame.
* Before any frame has been evaluated, these methods return the maximal set
* to which the selection can evaluate.
*
* There are two possible modes for how positions for dynamic selections are
* handled. In the default mode, posCount() can change, and for each frame,
* only the positions that are selected in that frame can be accessed. In a
* masked mode, posCount() remains constant, i.e., the positions are always
* evaluated for the maximal set, and SelectionPosition::selected() is used to
* determine whether a position is selected for a frame. The masked mode can
* be requested with SelectionOption::dynamicMask().
*
* The class also provides methods for printing out information: printInfo()
* and printDebugInfo(). These are mainly for internal use by Gromacs.
*
* This class works like a pointer type: copying and assignment is lightweight,
* and all copies work interchangeably, accessing the same internal data.
*
* Methods in this class do not throw.
*
* \see SelectionPosition
*
* \inpublicapi
* \ingroup module_selection
*/
class Selection
{
public:
/*! \brief
* Creates a selection wrapper that has no associated selection.
*
* Any attempt to call methods in the object before a selection is
* assigned results in undefined behavior.
* isValid() returns `false` for the selection until it is initialized.
*/
Selection() : sel_(nullptr) {}
/*! \brief
* Creates a new selection object.
*
* \param sel Selection data to wrap.
*
* Only for internal use by the selection module.
*/
explicit Selection(internal::SelectionData *sel) : sel_(sel) {}
//! Returns whether the selection object is initialized.
bool isValid() const { return sel_ != nullptr; }
//! Returns whether two selection objects wrap the same selection.
bool operator==(const Selection &other) const
{
return sel_ == other.sel_;
}
//! Returns whether two selection objects wrap different selections.
bool operator!=(const Selection &other) const
{
return !operator==(other);
}
//! Returns the name of the selection.
const char *name() const { return data().name(); }
//! Returns the string that was parsed to produce this selection.
const char *selectionText() const { return data().selectionText(); }
//! Returns true if the size of the selection (posCount()) is dynamic.
bool isDynamic() const { return data().isDynamic(); }
//! Returns the type of positions in the selection.
e_index_t type() const { return data().type(); }
//! Returns true if the selection only contains positions with a single atom each.
bool hasOnlyAtoms() const { return data().hasOnlyAtoms(); }
//! Returns `true` if the atom indices in the selection are in ascending order.
bool hasSortedAtomIndices() const { return data().hasSortedAtomIndices(); }
//! Total number of atoms in the selection.
int atomCount() const
{
return data().rawPositions_.m.mapb.nra;
}
//! Returns atom indices of all atoms in the selection.
ArrayRef<const int> atomIndices() const
{
return constArrayRefFromArray(sel_->rawPositions_.m.mapb.a,
sel_->rawPositions_.m.mapb.nra);
}
//! Number of positions in the selection.
int posCount() const { return data().posCount(); }
//! Access a single position.
SelectionPosition position(int i) const;
//! Returns coordinates for this selection as a continuous array.
ArrayRef<const rvec> coordinates() const
{
return constArrayRefFromArray(data().rawPositions_.x, posCount());
}
//! Returns whether velocities are available for this selection.
bool hasVelocities() const { return data().rawPositions_.v != nullptr; }
/*! \brief
* Returns velocities for this selection as a continuous array.
*
* Must not be called if hasVelocities() returns false.
*/
ArrayRef<const rvec> velocities() const
{
GMX_ASSERT(hasVelocities(), "Velocities accessed, but unavailable");
return constArrayRefFromArray(data().rawPositions_.v, posCount());
}
//! Returns whether forces are available for this selection.
bool hasForces() const { return sel_->rawPositions_.f != nullptr; }
/*! \brief
* Returns forces for this selection as a continuous array.
*
* Must not be called if hasForces() returns false.
*/
ArrayRef<const rvec> forces() const
{
GMX_ASSERT(hasForces(), "Forces accessed, but unavailable");
return constArrayRefFromArray(data().rawPositions_.f, posCount());
}
//! Returns masses for this selection as a continuous array.
ArrayRef<const real> masses() const
{
// posMass_ may have more entries than posCount() in the case of
// dynamic selections that don't have a topology
// (and thus the masses and charges are fixed).
GMX_ASSERT(data().posMass_.size() >= static_cast<size_t>(posCount()),
"Internal inconsistency");
return makeArrayRef(data().posMass_).subArray(0, posCount());
}
//! Returns charges for this selection as a continuous array.
ArrayRef<const real> charges() const
{
// posCharge_ may have more entries than posCount() in the case of
// dynamic selections that don't have a topology
// (and thus the masses and charges are fixed).
GMX_ASSERT(data().posCharge_.size() >= static_cast<size_t>(posCount()),
"Internal inconsistency");
return makeArrayRef(data().posCharge_).subArray(0, posCount());
}
/*! \brief
* Returns reference IDs for this selection as a continuous array.
*
* \see SelectionPosition::refId()
*/
ArrayRef<const int> refIds() const
{
return constArrayRefFromArray(data().rawPositions_.m.refid, posCount());
}
/*! \brief
* Returns mapped IDs for this selection as a continuous array.
*
* \see SelectionPosition::mappedId()
*/
ArrayRef<const int> mappedIds() const
{
return constArrayRefFromArray(data().rawPositions_.m.mapid, posCount());
}
//! Returns whether the covered fraction can change between frames.
bool isCoveredFractionDynamic() const { return data().isCoveredFractionDynamic(); }
//! Returns the covered fraction for the current frame.
real coveredFraction() const { return data().coveredFraction_; }
/*! \brief
* Allows passing a selection directly to neighborhood searching.
*
* When initialized this way, AnalysisNeighborhoodPair objects return
* indices that can be used to index the selection positions with
* position().
*
* Works exactly like if AnalysisNeighborhoodPositions had a
* constructor taking a Selection object as a parameter.
* See AnalysisNeighborhoodPositions for rationale and additional
* discussion.
*/
operator AnalysisNeighborhoodPositions() const;
/*! \brief
* Initializes information about covered fractions.
*
* \param[in] type Type of covered fraction required.
* \returns true if the covered fraction can be calculated for the
* selection.
*/
bool initCoveredFraction(e_coverfrac_t type)
{
return data().initCoveredFraction(type);
}
/*! \brief
* Sets whether this selection evaluates velocities for positions.
*
* \param[in] bEnabled If true, velocities are evaluated.
*
* If you request the evaluation, but then evaluate the selection for
* a frame that does not contain velocity information, results are
* undefined.
*
* \todo
* Implement it such that in the above case, hasVelocities() will
* return false for such frames.
*
* Does not throw.
*/
void setEvaluateVelocities(bool bEnabled)
{
data().flags_.set(efSelection_EvaluateVelocities, bEnabled);
}
/*! \brief
* Sets whether this selection evaluates forces for positions.
*
* \param[in] bEnabled If true, forces are evaluated.
*
* If you request the evaluation, but then evaluate the selection for
* a frame that does not contain force information, results are
* undefined.
*
* Does not throw.
*/
void setEvaluateForces(bool bEnabled)
{
data().flags_.set(efSelection_EvaluateForces, bEnabled);
}
/*! \brief
* Sets the ID for the \p i'th position for use with
* SelectionPosition::mappedId().
*
* \param[in] i Zero-based index
* \param[in] id Identifier to set.
*
* This method is not part of SelectionPosition because that interface
* only provides access to const data by design.
*
* This method can only be called after compilation, before the
* selection has been evaluated for any frame.
*
* \see SelectionPosition::mappedId()
*/
void setOriginalId(int i, int id);
/*! \brief
* Inits the IDs for use with SelectionPosition::mappedId() for
* grouping.
*
* \param[in] top Topology information
* (can be NULL if not required for \p type).
* \param[in] type Type of groups to generate.
* \returns Number of groups that were present in the selection.
* \throws InconsistentInputError if the selection positions cannot
* be assigned to groups of the given type.
*
* If `type == INDEX_ATOM`, the IDs are initialized to 0, 1, 2, ...,
* and the return value is the number of positions.
* If `type == INDEX_ALL`, all the IDs are initialized to 0, and the
* return value is one.
* If `type == INDEX_RES` or `type == INDEX_MOL`, the first position
* will get ID 0, and all following positions that belong to the same
* residue/molecule will get the same ID. The first position that
* belongs to a different residue/molecule will get ID 1, and so on.
* If some position contains atoms from multiple residues/molecules,
* i.e., the mapping is ambiguous, an exception is thrown.
* The return value is the number of residues/molecules that are
* present in the selection positions.
*
* This method is useful if the calling code needs to group the
* selection, e.g., for computing aggregate properties for each residue
* or molecule. It can then use this method to initialize the
* appropriate grouping, use the return value to allocate a
* sufficiently sized buffer to store the aggregated values, and then
* use SelectionPosition::mappedId() to identify the location where to
* aggregate to.
*
* \see setOriginalId()
* \see SelectionPosition::mappedId()
*/
int initOriginalIdsToGroup(const gmx_mtop_t *top, e_index_t type);
/*! \brief
* Prints out one-line description of the selection.
*
* \param[in] fp Where to print the information.
*
* The output contains the name of the selection, the number of atoms
* and the number of positions, and indication of whether the selection
* is dynamic.
*/
void printInfo(FILE *fp) const;
/*! \brief
* Prints out extended information about the selection for debugging.
*
* \param[in] fp Where to print the information.
* \param[in] nmaxind Maximum number of values to print in lists
* (-1 = print all).
*/
void printDebugInfo(FILE *fp, int nmaxind) const;
private:
internal::SelectionData &data()
{
GMX_ASSERT(sel_ != NULL,
"Attempted to access uninitialized selection");
return *sel_;
}
const internal::SelectionData &data() const
{
GMX_ASSERT(sel_ != NULL,
"Attempted to access uninitialized selection");
return *sel_;
}
/*! \brief
* Pointer to internal data for the selection.
*
* The memory for this object is managed by a SelectionCollection
* object, and the \ref Selection class simply provides a public
* interface for accessing the data.
*/
internal::SelectionData *sel_;
/*! \brief
* Needed to access the data to adjust flags.
*/
friend class SelectionOptionStorage;
};
/*! \brief
* Provides access to information about a single selected position.
*
* Each position has associated coordinates, and possibly velocities and forces
* if they have been requested and are available. It also has a set of atoms
* associated with it; typically the coordinates are the center-of-mass or
* center-of-geometry coordinates for that set of atoms. It is possible that
* there are not atoms associated if the selection has been provided as a fixed
* position.
*
* After the selection has been compiled, but not yet evaluated, the contents
* of the coordinate, velocity and force vectors are undefined.
*
* Default copy constructor and assignment operators are used, and work as
* intended: the copy references the same position and works identically.
*
* Methods in this class do not throw.
*
* \see Selection
*
* \inpublicapi
* \ingroup module_selection
*/
class SelectionPosition
{
public:
/*! \brief
* Constructs a wrapper object for given selection position.
*
* \param[in] sel Selection from which the position is wrapped.
* \param[in] index Zero-based index of the position to wrap.
*
* Asserts if \p index is out of range.
*
* Only for internal use of the library. To obtain a SelectionPosition
* object in other code, use Selection::position().
*/
SelectionPosition(const internal::SelectionData &sel, int index)
: sel_(&sel), i_(index)
{
GMX_ASSERT(index >= 0 && index < sel.posCount(),
"Invalid selection position index");
}
/*! \brief
* Returns type of this position.
*
* Currently always returns the same as Selection::type().
*/
e_index_t type() const { return sel_->type(); }
//! Returns coordinates for this position.
const rvec &x() const
{
return sel_->rawPositions_.x[i_];
}
/*! \brief
* Returns velocity for this position.
*
* Must not be called if Selection::hasVelocities() returns false.
*/
const rvec &v() const
{
GMX_ASSERT(sel_->rawPositions_.v != NULL,
"Velocities accessed, but unavailable");
return sel_->rawPositions_.v[i_];
}
/*! \brief
* Returns force for this position.
*
* Must not be called if Selection::hasForces() returns false.
*/
const rvec &f() const
{
GMX_ASSERT(sel_->rawPositions_.f != NULL,
"Velocities accessed, but unavailable");
return sel_->rawPositions_.f[i_];
}
/*! \brief
* Returns total mass for this position.
*
* Returns the total mass of atoms that make up this position.
* If there are no atoms associated or masses are not available,
* returns unity.
*/
real mass() const
{
return sel_->posMass_[i_];
}
/*! \brief
* Returns total charge for this position.
*
* Returns the sum of charges of atoms that make up this position.
* If there are no atoms associated or charges are not available,
* returns zero.
*/
real charge() const
{
return sel_->posCharge_[i_];
}
//! Returns the number of atoms that make up this position.
int atomCount() const
{
return sel_->rawPositions_.m.mapb.index[i_ + 1]
- sel_->rawPositions_.m.mapb.index[i_];
}
//! Return atom indices that make up this position.
ArrayRef<const int> atomIndices() const
{
const int *atoms = sel_->rawPositions_.m.mapb.a;
if (atoms == nullptr)
{
return ArrayRef<const int>();
}
const int first = sel_->rawPositions_.m.mapb.index[i_];
return constArrayRefFromArray(&atoms[first], atomCount());
}
/*! \brief
* Returns whether this position is selected in the current frame.
*
* The return value is equivalent to \c refid() == -1. Returns always
* true if SelectionOption::dynamicMask() has not been set.
*
* \see refId()
*/
bool selected() const
{
return refId() >= 0;
}
/*! \brief
* Returns reference ID for this position.
*
* For dynamic selections, this provides means to associate positions
* across frames. After compilation, these IDs are consequently
* numbered starting from zero. For each frame, the ID then reflects
* the location of the position in the original array of positions.
* If SelectionOption::dynamicMask() has been set for the parent
* selection, the IDs for positions not present in the current
* selection are set to -1, otherwise they are removed completely.
*
* Example:
* If a dynamic selection consists of at most three positions, after
* compilation refId() will return 0, 1, 2 for them, respectively.
* If for a particular frame, only the first and the third are present,
* refId() will return 0, 2.
* If SelectionOption::dynamicMask() has been set, all three positions
* can be accessed also for that frame and refId() will return 0, -1,
* 2.
*/
int refId() const
{
return sel_->rawPositions_.m.refid[i_];
}
/*! \brief
* Returns mapped ID for this position.
*
* Returns ID of the position that corresponds to that set with
* Selection::setOriginalId().
*
* If for an array \c id, \c setOriginalId(i, id[i]) has been called
* for each \c i, then it always holds that
* \c mappedId()==id[refId()].
*
* Selection::setOriginalId() has not been called, the default values
* are dependent on type():
* - ::INDEX_ATOM: atom indices
* - ::INDEX_RES: residue indices
* - ::INDEX_MOL: molecule indices
* .
* All the default values are zero-based.
*/
int mappedId() const
{
return sel_->rawPositions_.m.mapid[i_];
}
/*! \brief
* Allows passing a selection position directly to neighborhood searching.
*
* When initialized this way, AnalysisNeighborhoodPair objects return
* the index that can be used to access this position using
* Selection::position().
*
* Works exactly like if AnalysisNeighborhoodPositions had a
* constructor taking a SelectionPosition object as a parameter.
* See AnalysisNeighborhoodPositions for rationale and additional
* discussion.
*/
operator AnalysisNeighborhoodPositions() const;
private:
const internal::SelectionData *sel_;
int i_;
};
inline SelectionPosition
Selection::position(int i) const
{
return SelectionPosition(data(), i);
}
} // namespace gmx
#endif
|