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 at 14 Oct 2013
021 * Author: ap3
022 */
023
024package demo;
025
026import org.biojava.nbio.structure.align.client.StructureName;
027import org.biojava.nbio.structure.align.util.UserConfiguration;
028import org.biojava.nbio.structure.cath.CathDatabase;
029import org.biojava.nbio.structure.cath.CathDomain;
030import org.biojava.nbio.structure.cath.CathInstallation;
031import org.biojava.nbio.structure.cath.CathSegment;
032import org.biojava.nbio.structure.gui.BiojavaJmol;
033import org.biojava.nbio.structure.StructureIO;
034
035import java.util.List;
036
037public class DemoShowCATHDomain {
038
039
040        private static final String DEFAULT_SCRIPT ="select * ; cartoon on; spacefill off; wireframe off; select ligands; wireframe on; spacefill on;";
041        private static final String[] colors = new String[]{"red","green","blue","yellow"};
042
043        public static void main(String[] args){
044
045                UserConfiguration config = new UserConfiguration();
046                config.setPdbFilePath("/tmp/");
047
048                String pdbID = "1DAN";
049
050                CathDatabase cath = new CathInstallation(config.getPdbFilePath());
051
052                List<CathDomain> domains = cath.getDomainsForPdb(pdbID);
053
054                try {
055
056                        // show the structure in 3D
057                        BiojavaJmol jmol = new BiojavaJmol();
058                        jmol.setStructure(StructureIO.getStructure(pdbID));
059                        jmol.evalString(DEFAULT_SCRIPT);
060
061                        System.out.println("got " + domains.size() + " domains");
062
063                        // now color the domains on the structure
064                        int colorpos = -1;
065
066                        for ( CathDomain domain : domains){
067
068                                colorpos++;
069
070                                showDomain(jmol, domain,colorpos);
071                        }
072
073
074                } catch (Exception e) {
075                        // TODO Auto-generated catch block
076                        e.printStackTrace();
077                }
078
079        }
080
081
082
083        private static void showDomain(BiojavaJmol jmol, CathDomain domain, int colorpos) {
084                List<CathSegment> segments = domain.getSegments();
085
086                StructureName key = new StructureName(domain.getDomainName());
087                String chainId = key.getChainId();
088
089                String color = colors[colorpos];
090
091                System.out.println(" * domain " + domain.getDomainName() + " has # segments: " + domain.getSegments().size() + " color: " + color);
092
093                for ( CathSegment segment : segments){
094                        System.out.println("   * " + segment);
095                        String start = segment.getStart();
096
097                        String stop = segment.getStop();
098
099                        String script = "select " + start + "-" + stop+":"+chainId + "; color " + color +";";
100
101                        jmol.evalString(script );
102                }
103
104        }
105
106}