|
| 1 | +/* |
| 2 | + * BioJava development code |
| 3 | + * |
| 4 | + * This code may be freely distributed and modified under the |
| 5 | + * terms of the GNU Lesser General Public Licence. This should |
| 6 | + * be distributed with the code. If you do not have a copy, |
| 7 | + * see: |
| 8 | + * |
| 9 | + * http://www.gnu.org/copyleft/lesser.html |
| 10 | + * |
| 11 | + * Copyright for this code is held jointly by the individual |
| 12 | + * authors. These should be listed in @author doc comments. |
| 13 | + * |
| 14 | + * For more information on the BioJava project and its aims, |
| 15 | + * or to join the biojava-l mailing list, visit the home page |
| 16 | + * at: |
| 17 | + * |
| 18 | + * http://www.biojava.org/ |
| 19 | + * |
| 20 | + * Created on Jul 6, 2016 |
| 21 | + * Author: blivens |
| 22 | + * |
| 23 | + */ |
| 24 | + |
| 25 | +package org.biojava.http.routes; |
| 26 | + |
| 27 | +import org.biojava.http.BioJavaRoutes; |
| 28 | +import org.biojava.http.models.CESymmParams; |
| 29 | +import org.biojava.nbio.structure.Atom; |
| 30 | +import org.biojava.nbio.structure.Structure; |
| 31 | +import org.biojava.nbio.structure.StructureIO; |
| 32 | +import org.biojava.nbio.structure.StructureTools; |
| 33 | +import org.biojava.nbio.structure.symmetry.internal.CeSymm; |
| 34 | +import org.biojava.nbio.structure.symmetry.internal.CeSymmResult; |
| 35 | +import org.slf4j.Logger; |
| 36 | +import org.slf4j.LoggerFactory; |
| 37 | + |
| 38 | +import spark.ModelAndView; |
| 39 | +import spark.Request; |
| 40 | +import spark.Response; |
| 41 | +import spark.TemplateViewRoute; |
| 42 | + |
| 43 | +/** |
| 44 | + * Handle requests for {@link BioJavaRoutes#MMCIF} |
| 45 | + * @author Spencer Bliven |
| 46 | + * |
| 47 | + */ |
| 48 | +public class CESymmRoute implements TemplateViewRoute { |
| 49 | + public static Logger logger = LoggerFactory.getLogger(CESymmRoute.class); |
| 50 | + |
| 51 | + @Override |
| 52 | + public ModelAndView handle(Request request, Response response) throws Exception { |
| 53 | + String id = request.params(":id"); |
| 54 | + if(id == null) { |
| 55 | + response.status(404); |
| 56 | + logger.error("null id"); |
| 57 | + return null; |
| 58 | + } |
| 59 | + try { |
| 60 | + Structure s = StructureIO.getStructure(id); |
| 61 | + if(s == null) { |
| 62 | + response.status(404); |
| 63 | + logger.error("null structure for "+id); |
| 64 | + return null; |
| 65 | + } |
| 66 | + Atom[] ca = StructureTools.getRepresentativeAtomArray(s); |
| 67 | + CeSymmResult result = CeSymm.analyze(ca); |
| 68 | + |
| 69 | + CESymmParams params = new CESymmParams(result); |
| 70 | + return new ModelAndView(params, "cesymm.html.hbs"); |
| 71 | + } catch(Exception e) { |
| 72 | + logger.error("Error",e); |
| 73 | + response.status(404); |
| 74 | + return null; |
| 75 | + } |
| 76 | + } |
| 77 | + |
| 78 | +} |
0 commit comments