001/* 002 * BioJava development code 003 * 004 * This code may be freely distributed and modified under the 005 * terms of the GNU Lesser General Public Licence. This should 006 * be distributed with the code. If you do not have a copy, 007 * see: 008 * 009 * http://www.gnu.org/copyleft/lesser.html 010 * 011 * Copyright for this code is held jointly by the individual 012 * authors. These should be listed in @author doc comments. 013 * 014 * For more information on the BioJava project and its aims, 015 * or to join the biojava-l mailing list, visit the home page 016 * at: 017 * 018 * http://www.biojava.org/ 019 * 020 */ 021package org.biojava.nbio.structure.contact; 022 023import org.biojava.nbio.structure.Group; 024 025import java.io.Serializable; 026import java.util.ArrayList; 027import java.util.List; 028 029/** 030 * A pair of residues that are in contact 031 * @author duarte_j 032 * 033 */ 034public class GroupContact implements Serializable { 035 036 037 private static final long serialVersionUID = 1L; 038 039 private Pair<Group> pair; 040 041 private List<AtomContact> atomContacts; 042 043 public GroupContact() { 044 atomContacts = new ArrayList<AtomContact>(); 045 } 046 047 public void addAtomContact(AtomContact atomContact) { 048 atomContacts.add(atomContact); 049 } 050 051 public Pair<Group> getPair() { 052 return pair; 053 } 054 055 public void setPair(Pair<Group> pair) { 056 this.pair = pair; 057 } 058 059 public double getMinDistance() { 060 if (atomContacts.size()==0) return 0; 061 062 double minDistance = Double.MAX_VALUE; 063 for (AtomContact atomContact:atomContacts) { 064 if (atomContact.getDistance()<minDistance) 065 minDistance = atomContact.getDistance(); 066 } 067 return minDistance; 068 } 069 070 public int getNumAtomContacts() { 071 return atomContacts.size(); 072 } 073 074 public List<AtomContact> getAtomContacts() { 075 return atomContacts; 076 } 077 078 /** 079 * Returns the list of atom contacts in this GroupContact that are within the given distance. 080 * @param distance 081 * @return 082 */ 083 public List<AtomContact> getContactsWithinDistance(double distance) { 084 085 List<AtomContact> list = new ArrayList<AtomContact>(); 086 for (AtomContact contact:this.atomContacts) { 087 if (contact.getDistance()<distance) { 088 list.add(contact); 089 } 090 } 091 return list; 092 } 093 094 @Override 095 public String toString() { 096 return pair.getFirst().getResidueNumber()+","+pair.getSecond().getResidueNumber(); 097 } 098}