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 * Created on Mar 1, 2006
021 *
022 */
023package org.biojava.nbio.structure.align.helper;
024
025import java.util.ArrayList;
026import java.util.Collections;
027import java.util.Iterator;
028import java.util.List;
029
030
031/** A utility class that defines which set of atoms are considered
032 * to be on equivalent positions.
033 *
034 *
035 */
036public class JointFragments {
037
038
039                double rms;
040
041                List<int[]> idxlist;
042                public JointFragments(){
043                        idxlist = new ArrayList<int[]>();
044                        rms = 999;
045                }
046
047                /**
048                 * Stores the alignment between the residues of several fragments.
049                 * Each int[] stores the residue numbers of several equivalent residues.
050                 */
051                public void setIdxlist(List<int[]> idxs) {
052                        Iterator<int[]> iter = idxs.iterator();
053                        while (iter.hasNext()){
054                                int[] e = iter.next();
055                                idxlist.add(e);
056                        }
057                }
058
059
060
061                public double getRms() {
062                        return rms;
063                }
064
065                public void setRms(double rms) {
066                        this.rms = rms;
067                }
068
069                public List<int[]> getIdxlist(){
070                        return idxlist;
071                }
072                public void add(int p1, int p2,int start,int end){
073                        //System.out.println("JointFragments add " +p1 + " " + p2 + " " + start + " " + end);
074                        for ( int k = start;k< end ; k++){
075                                //e = (f[0]+k,f[1]+k)
076                                //e = (f[0]+k,f[1]+k);
077                                int[] e = new int[] {p1+k,p2+k};
078
079                                // check if already known ...
080                                Iterator<int[]> iter = idxlist.iterator();
081                                while (iter.hasNext()){
082                                        int[] kno = iter.next();
083                                        if ((kno[0] == e[0]) && ( kno[1] == e[1])){
084                                                System.err.println("already known index pair, not adding a 2nd time." + e[0] + " " + e[1]);
085                                                return;
086                                        }
087                                }
088                                idxlist.add(e);
089                                Collections.sort(idxlist, new IdxComparator());
090                        }
091                }
092
093
094                @Override
095                public String toString(){
096                        String s = "Joint Fragment idxlist len: " +idxlist.size();
097                        return s;
098                }
099
100
101}