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 Sep 12, 2007
021 *
022 */
023package org.biojava.nbio.structure.io;
024
025import org.biojava.nbio.structure.*;
026
027import java.util.ArrayList;
028import java.util.List;
029
030/** Converts full atom representations to Calpha only ones.
031 *
032 * @author Andreas Prlic
033 * @version %I% %G%
034 */
035public class CAConverter {
036
037
038        /** Convert a List of chain objects to another List of chains, containing Representative atoms only.
039         *
040         * @param chains list of chains
041         * @return a list of chains
042         * @since Biojava 4.1.0
043         */
044        public static List<Chain> getRepresentativeAtomsOnly(List<Chain> chains){
045                List<Chain> newChains = new ArrayList<Chain>();
046
047                for (Chain chain : chains){
048                        Chain newChain = getRepresentativeAtomsOnly(chain);
049                        newChains.add(newChain);
050                }
051
052                return newChains;
053        }
054
055        /**
056         * Convert a Chain to a new Chain containing C-alpha atoms only.
057         *
058         * @param chain to convert
059         * @return a new chain containing Amino acids with C-alpha only.
060         * @since Biojava 4.1.0
061         */
062        public static Chain getRepresentativeAtomsOnly(Chain chain){
063
064                Chain newChain = new ChainImpl();
065                newChain.setId(chain.getId());
066                newChain.setName(chain.getName());
067                newChain.setEntityInfo(chain.getEntityInfo());
068
069                List<Group> groups = chain.getAtomGroups();
070
071                grouploop:
072                        for (Group g: groups){
073                                List<Atom> atoms = g.getAtoms();
074
075                                if ( ! (g instanceof AminoAcid))
076                                        continue;
077
078                                for (Atom a : atoms){
079
080                                        if ( a.getName().equals(StructureTools.CA_ATOM_NAME) && a.getElement()==Element.C){
081                                                // we got a CA atom in this group!
082                                                AminoAcid n = new AminoAcidImpl();
083                                                n.setPDBName(g.getPDBName());
084                                                n.setResidueNumber(g.getResidueNumber());
085                                                n.addAtom(a);
086                                                newChain.addGroup(n);
087                                                continue grouploop;
088
089                                        }
090                                }
091
092                        }
093                return newChain;
094        }
095}