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.symmetry.core;
022
023import org.biojava.nbio.structure.geometry.CalcPoint;
024import javax.vecmath.Matrix4d;
025import javax.vecmath.Point3d;
026
027import java.util.ArrayList;
028import java.util.List;
029
030public class HelixExtender {
031        private QuatSymmetrySubunits subunits = null;
032        private Helix helix = null;
033
034        public HelixExtender(QuatSymmetrySubunits subunits, Helix helix) {
035                this.subunits = subunits;
036                this.helix = helix;
037        }
038
039        public Point3d[] extendHelix(int steps) {
040                List<List<Integer>> layerLines = helix.getLayerLines();
041
042                // get list of subunit indices to be used for helix extension
043                List<Integer> indices = new ArrayList<Integer>();
044                for (List<Integer> line: layerLines) {
045                        if (steps < 0) {
046                                indices.add(line.get(0));
047                        } else if (steps > 0) {
048                                indices.add(line.get(line.size()-1));
049                        }
050                }
051                System.out.println("Extending subunits: " + indices);
052
053                List<Point3d> points = new ArrayList<Point3d>();
054                Matrix4d transformation = helix.getTransformation();
055                for (int index: indices) {
056                Point3d[] trace = subunits.getTraces().get(index);
057                Point3d[] copy = CalcPoint.clonePoint3dArray(trace);
058                    for (int i = 0; i < Math.abs(steps); i++) {
059                        CalcPoint.transform(transformation, copy);
060                    }
061                    for (Point3d p: copy) {
062                        points.add(p);
063                    }
064                }
065                return points.toArray(new Point3d[0]);
066        }
067
068}