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 demo;
022
023import org.biojava.nbio.structure.Structure;
024import org.biojava.nbio.structure.StructureException;
025import org.biojava.nbio.structure.align.gui.jmol.StructureAlignmentJmol;
026import org.biojava.nbio.structure.align.util.AtomCache;
027import org.biojava.nbio.structure.io.FileParsingParameters;
028import org.biojava.nbio.structure.symmetry.analysis.CalcBioAssemblySymmetry;
029import org.biojava.nbio.structure.symmetry.core.AxisAligner;
030import org.biojava.nbio.structure.symmetry.core.QuatSymmetryDetector;
031import org.biojava.nbio.structure.symmetry.core.QuatSymmetryParameters;
032import org.biojava.nbio.structure.symmetry.core.QuatSymmetryResults;
033import org.biojava.nbio.structure.symmetry.jmolScript.JmolSymmetryScriptGenerator;
034import org.biojava.nbio.structure.symmetry.jmolScript.JmolSymmetryScriptGeneratorPointGroup;
035
036import java.io.IOException;
037import java.util.List;
038
039/**
040 * Created by ap3 on 02/04/2015.
041 */
042public class DemoOrientBioAssembly {
043
044        public static void main(String[] args){
045
046
047                //String[] pdbIDs = new String[]{"4HHB","4AQ5","1LTI","1STP","4F88","2W6E","2LXC","3OE7","4INU","4D8s","4EAR","4IYQ","3ZKR"};
048
049                String[] pdbIDs = new String[]{"4x2s"};
050
051                int bioAssemblyNr = 1;
052
053                /*
054                        Local symmetry
055
056                        2WPD has 2 local symmetries.
057
058                        Other examples with a single local symmetry are:
059                        4F88 – local C8
060                        1LTI – local C5
061                        2W6E – local C3
062                        2LXC – local C2
063                        3OE7 – local C3
064
065                        Local Pseudosymmetry, structure only
066
067                        3ZDY
068                        3ZDX
069
070                        Helical
071
072                        1B47
073
074                 */
075
076                for ( String pdbID : pdbIDs)
077                {
078                        try {
079
080                                runPDB(pdbID,bioAssemblyNr);
081
082                        } catch (Exception e) {
083                                // TODO Auto-generated catch block
084                                e.printStackTrace();
085                        }
086                }
087
088        }
089
090        public static void runPDB(String pdbID, int bioAssemblyNr) throws IOException, StructureException {
091
092
093
094                pdbID = pdbID.toLowerCase();
095
096
097                //Structure s = StructureIO.getBiologicalAssembly(pdbID, bioAssemblyNr);
098                Structure s = readStructure(pdbID, bioAssemblyNr);
099
100                QuatSymmetryParameters parameters = new QuatSymmetryParameters();
101                parameters.setOnTheFly(true);
102                parameters.setVerbose(true);
103
104
105                CalcBioAssemblySymmetry calc = new CalcBioAssemblySymmetry(s, parameters);
106
107                QuatSymmetryDetector detector = calc.orient();
108
109
110                List<QuatSymmetryResults> globalResults = detector.getGlobalSymmetry();
111
112                System.out.println("# of global results: " + globalResults.size());
113
114                List<List<QuatSymmetryResults>> localResults = detector.getLocalSymmetries();
115
116
117
118                showResults(s, pdbID + "[" + bioAssemblyNr + "] Global", globalResults);
119
120
121                for (int counter = 0;counter < localResults.size() ; counter++){
122                        List<QuatSymmetryResults> localResultsL = localResults.get(counter);
123
124                        showResults(s,pdbID + "[" + bioAssemblyNr + "] Local #" + (counter+1) , localResultsL);
125                }
126
127                //determine default view:
128                boolean defaultFound = false;
129
130                for ( QuatSymmetryResults r : globalResults) {
131                        System.out.println(r.getSymmetry());
132                        //                      if (! r.getRotationGroup().getPointGroup().equals("C1")) {
133                        //                              defaultResult = r;
134                        //                              defaultFound = true;
135                        //                      } else if ( r.getSubunits().isPseudoSymmetric()) {
136                        //                              defaultResult = r;
137                        //                              defaultFound  = true;
138                        //                      }
139                        if (r.isPreferredResult()) {
140
141                                defaultFound = true;
142                                System.out.println("!!!");
143                        }
144
145                }
146                if ( ! defaultFound) {
147                        for (List<QuatSymmetryResults> localResultSet : localResults) {
148                                for ( QuatSymmetryResults r : localResultSet) {
149                                        System.out.println(r.getSymmetry());
150                                        if ( r.isPreferredResult()) {
151
152                                        }
153                                }
154                        }
155                }
156
157
158        }
159
160        private static void showResults(Structure s, String title,
161                                                                        List<QuatSymmetryResults> results) {
162
163
164                int count = 0 ;
165                for (QuatSymmetryResults result: results) {
166
167                        String longTitle = title + " count:"+ count + " [" + result.getSubunits().getStoichiometry() +"]";
168
169                        String script = "set defaultStructureDSSP true; set measurementUnits ANGSTROMS;  select all;  spacefill off; wireframe off; " +
170                                        "backbone off; cartoon on; color cartoon structure; color structure;  select ligand;wireframe 0.16;spacefill 0.5; " +
171                                        "color cpk ; select all; model 0;set antialiasDisplay true; autobond=false;save STATE state_1;" ;
172                        count++;
173
174                        if ( result.getSubunits().isPseudoSymmetric()) {
175                                longTitle += " pseudosymmetric!";
176                        } else {
177                                System.out.println(" not pseudosymmetric!");
178
179                        }
180
181                        AxisAligner aligner = AxisAligner.getInstance(result);
182
183                        // use factory method to get point group specific instance of script generator
184                        JmolSymmetryScriptGenerator scriptGenerator = JmolSymmetryScriptGeneratorPointGroup.getInstance(aligner, "g");
185
186                        script += scriptGenerator.getOrientationWithZoom(0);
187                        script += scriptGenerator.drawPolyhedron();
188                        script += scriptGenerator.drawAxes();
189                        script += scriptGenerator.colorBySymmetry();
190
191
192                        longTitle += " M:" + result.getMethod();
193
194                        longTitle += String.format(" SEQ: %.2f - %.2f", result.getSubunits().getMinSequenceIdentity() ,result.getSubunits().getMaxSequenceIdentity());
195
196
197
198
199
200                        script += "draw axes* on; draw poly* on;";
201
202
203                        // show in Jmol...
204
205                        StructureAlignmentJmol jmol = new StructureAlignmentJmol();
206                        jmol.setStructure(s);
207
208                        jmol.setTitle(longTitle);
209                        jmol.evalString(script);
210                }
211
212
213        }
214
215
216
217        private static Structure  readStructure(String pdbId, int bioAssemblyId) {
218                // initialize the PDB_DIR env variable
219                AtomCache cache = new AtomCache();
220                cache.setUseMmCif(true);
221
222                FileParsingParameters params = new FileParsingParameters();
223                params.setParseCAOnly(true);
224                params.setAtomCaThreshold(Integer.MAX_VALUE);
225                cache.setFileParsingParams(params);
226
227                Structure structure = null;
228                try {
229                        structure = cache.getBiologicalAssembly(pdbId, bioAssemblyId);
230                } catch (IOException e) {
231                        // TODO Auto-generated catch block
232                        e.printStackTrace();
233                } catch (StructureException e) {
234                        // TODO Auto-generated catch block
235                        e.printStackTrace();
236                }
237
238                return structure;
239        }
240}