Class AtomContactSet

java.lang.Object
org.biojava.nbio.structure.contact.AtomContactSet
All Implemented Interfaces:
Serializable, Iterable<AtomContact>

public class AtomContactSet extends Object implements Serializable, Iterable<AtomContact>
A set of atom-atom contacts to hold the results of intra and inter-chain contact calculations

Contacts are keyed by the ordered pair of AtomIdentifiers of the 2 atoms, i.e. the pair (a,b) and the pair (b,a) are 2 different keys. Thus look-ups (hasContact(Atom, Atom), getContact(Atom, Atom)) must give the 2 atoms in the same order in which the contact was calculated. The order produced by the calculation (Grid) is:

  • for contacts within a single set of atoms (e.g. the intra-chain contacts of StructureTools.getAtomsInContact(Chain, double)), the atom that comes first in the atom array is the first member of the pair
  • for contacts between 2 sets of atoms (e.g. the inter-chain contacts of StructureTools.getAtomsInContact(Chain, Chain, double, boolean), or a StructureInterface), the atom belonging to the first set is the first member of the pair

Note that the order is not the order of PDB serials or of any other property of the atoms themselves: it is only the order in which the atoms were given to the calculation.

Author:
duarte_j
See Also:
  • Constructor Details

    • AtomContactSet

      public AtomContactSet(double cutoff)
    • AtomContactSet

      public AtomContactSet(double cutoff, int expectedSize)
      Creates an AtomContactSet sized to hold the given number of contacts, so that the underlying map doesn't have to be repeatedly resized and rehashed as contacts are added. Contact calculations produce hundreds of thousands of contacts for a large structure, where the repeated rehashing that growing from the default capacity entails is a significant part of the cost.
      Parameters:
      cutoff - the distance cutoff
      expectedSize - the number of contacts expected to be added. Only affects performance: an over-estimate merely leaves the map larger than it needs to be.
  • Method Details

    • add

      public void add(AtomContact contact)
      Adds the given contact to this set, keyed by the ordered pair of its 2 atoms. If a contact with the same ordered pair of atoms is already present it is replaced.
      Parameters:
      contact - the contact to add
    • addAll

      public void addAll(Collection<AtomContact> list)
      Adds all given contacts to this set, see add(AtomContact).
      Parameters:
      list - the contacts to add
    • hasContact

      public boolean hasContact(Atom atom1, Atom atom2)
      Tells whether a contact exists between the 2 given atoms, in the given order.

      The 2 atoms have to be passed in the same order in which the contacts of this set were calculated, otherwise this returns false even if the 2 atoms are within the distance cutoff. See the class documentation for the ordering convention. If the order is not known, both orders have to be queried.

      Parameters:
      atom1 - the first atom of the pair
      atom2 - the second atom of the pair
      Returns:
      true if the 2 atoms are in contact in the given order, false otherwise
      See Also:
    • hasContact

      public boolean hasContact(AtomIdentifier atomId1, AtomIdentifier atomId2)
      Tells whether a contact exists between the 2 given atom identifiers, in the given order, see hasContact(Atom, Atom).
      Parameters:
      atomId1 - the identifier of the first atom of the pair
      atomId2 - the identifier of the second atom of the pair
      Returns:
      true if the 2 atoms are in contact in the given order, false otherwise
    • getContact

      public AtomContact getContact(Atom atom1, Atom atom2)
      Returns the contact between the 2 given atoms in the given order, or null if there is no such contact in this set.

      As in hasContact(Atom, Atom) the order of the 2 atoms matters: they have to be passed in the same order in which the contacts of this set were calculated, otherwise null is returned even if the 2 atoms are within the distance cutoff. See the class documentation for the ordering convention.

      Parameters:
      atom1 - the first atom of the pair
      atom2 - the second atom of the pair
      Returns:
      the contact between the 2 atoms in the given order, or null if there is none
    • size

      public int size()
    • iterator

      public Iterator<AtomContact> iterator()
      Specified by:
      iterator in interface Iterable<AtomContact>
    • hasContactsWithinDistance

      public boolean hasContactsWithinDistance(double distance)
      Returns true if at least 1 contact from this set is within the given distance. Note that if the distance given is larger than the distance cutoff used to calculate the contacts then nothing will be found.
      Parameters:
      distance -
      Returns:
      Throws:
      IllegalArgumentException - if given distance is larger than distance cutoff used for calculation of contacts
    • getContactsWithinDistance

      public List<AtomContact> getContactsWithinDistance(double distance)
      Returns the list of contacts from this set that are within the given distance.
      Parameters:
      distance -
      Returns:
      Throws:
      IllegalArgumentException - if given distance is larger than distance cutoff used for calculation of contacts