@Test public void testJmolPageGenerator() { List<Residue> residues = new ArrayList<>(); Residue res1 = new Residue(); Residue res2 = new Residue(); Residue res3 = new Residue(); Residue res4 = new Residue(); Residue res7 = new Residue(); res1.setPdbResidueNumber("1"); res1.setSide(false); res2.setPdbResidueNumber("2A"); res2.setSide(false); res3.setPdbResidueNumber("3"); res3.setSide(false); res4.setPdbResidueNumber("4"); res4.setSide(false); res7.setPdbResidueNumber(null); res7.setSide(false); res1.setRegion(ResidueBurialDB.CORE_GEOMETRY); res2.setRegion(ResidueBurialDB.CORE_GEOMETRY); res3.setRegion(ResidueBurialDB.RIM_EVOLUTIONARY); res4.setRegion(ResidueBurialDB.RIM_EVOLUTIONARY); res4.setRegion(ResidueBurialDB.RIM_EVOLUTIONARY); res7.setRegion(ResidueBurialDB.RIM_EVOLUTIONARY); Residue res5 = new Residue(); Residue res6 = new Residue(); res5.setPdbResidueNumber("5"); res5.setSide(true); res6.setPdbResidueNumber("6"); res6.setSide(true); res5.setRegion(ResidueBurialDB.CORE_GEOMETRY); res6.setRegion(ResidueBurialDB.CORE_GEOMETRY); residues.add(res1); residues.add(res2); residues.add(res3); residues.add(res4); residues.add(res5); residues.add(res6); residues.add(res7); Interface interfData = new Interface(); interfData.setChain1("A"); interfData.setChain2("B"); interfData.setResidues(residues); AssemblyContent ac = new AssemblyContent(); ac.setChainIds("A_0,B_0,A_1,B_1"); Assembly assemblyData = new Assembly(); List<AssemblyContent> acs = new ArrayList<>(); acs.add(ac); assemblyData.setAssemblyContents(acs); StringWriter out = new StringWriter(); try( PrintWriter pw = new PrintWriter(out) ) { JmolPageGenerator.generatePage("test title", "200", "1smt", "http: "/ngl.embedded.min.js",pw, "/"); } out.flush(); String thepage = out.toString(); logger.debug("Generated JmolPage HTML:\n{}",thepage); assertFalse(thepage.contains("null")); assertFalse(thepage.contains("&amp;")); Pattern p = Pattern.compile(".*\":\\w.*", Pattern.DOTALL); Matcher m = p.matcher(thepage); assertFalse(m.matches()); p = Pattern.compile("\"(#\\w+)\"", Pattern.DOTALL); m = p.matcher(thepage); while (m.find()) { String colorStr = m.group(1); assertEquals(7, colorStr.length()); assertEquals('#', colorStr.charAt(0)); } assertFalse(thepage.contains("0x")); p = Pattern.compile(".*or 2\\^A.*", Pattern.DOTALL); m = p.matcher(thepage); assertTrue(m.matches()); }
public static void generatePage(String title, String size, String jobId, String serverUrl, String fileName, Interface interfData, Assembly assemblyData, String nglJsUrl, PrintWriter out, String webappRoot) { boolean isCif = true; if (fileName.endsWith("cif")) { isCif = true; } else if (fileName.endsWith("pdb")) { isCif = false; } String jsVariables = generateSelectionVarsNgl(interfData, assemblyData, isCif); double maxEntropy = Math.log(EppicParams.DEF_ENTROPY_ALPHABET.getNumLetters()) / Math.log(2); if (!webappRoot.endsWith("/")) webappRoot = webappRoot + "/"; StringBuilder fileUrl = new StringBuilder(); fileUrl.append(serverUrl).append(webappRoot).append("ewui/").append(FileDownloadServlet.SERVLET_NAME).append("?") .append(FileDownloadServlet.PARAM_TYPE).append("="); if (assemblyData!=null) { fileUrl.append(FileDownloadServlet.TYPE_VALUE_ASSEMBLY).append("&").append(FileDownloadServlet.PARAM_ID).append("=").append(jobId) .append("&").append(FileDownloadServlet.PARAM_ASSEMBLY_ID).append("=").append(assemblyData.getId()); } else if (interfData != null) { fileUrl.append(FileDownloadServlet.TYPE_VALUE_INTERFACE).append("&").append(FileDownloadServlet.PARAM_ID).append("=").append(jobId) .append("&").append(FileDownloadServlet.PARAM_INTERFACE_ID).append("=").append(interfData.getInterfaceId()); } else { logger.error("Illegal state. Either assembly or interface data must be not null"); } fileUrl.append("&").append(FileDownloadServlet.PARAM_COORDS_FORMAT).append("=").append(FileDownloadServlet.COORDS_FORMAT_VALUE_CIF); Map<String,Object> page = new HashMap<>(); page.put("title", title); page.put("libURL", nglJsUrl); page.put("jsURL", webappRoot + EPPIC_NGL_JS_FUNCTIONS); page.put("cssUrl", webappRoot + CSSFILE); page.put("fileURL", fileUrl.toString()); page.put("jsVariables", jsVariables); page.put("maxEntropy", String.format("%.4f",maxEntropy)); page.put("size", size); MustacheFactory mf = new DefaultMustacheFactory(); String template = LatticeGUIMustache.expandTemplatePath(TEMPLATE_NGL); Mustache mustache = mf.compile(template); try { mustache.execute(out, page) .flush(); } catch (IOException e) { logger.error("Error generating output from template "+template,e); } }
JmolPageGenerator { public static void generatePage(String title, String size, String jobId, String serverUrl, String fileName, Interface interfData, Assembly assemblyData, String nglJsUrl, PrintWriter out, String webappRoot) { boolean isCif = true; if (fileName.endsWith("cif")) { isCif = true; } else if (fileName.endsWith("pdb")) { isCif = false; } String jsVariables = generateSelectionVarsNgl(interfData, assemblyData, isCif); double maxEntropy = Math.log(EppicParams.DEF_ENTROPY_ALPHABET.getNumLetters()) / Math.log(2); if (!webappRoot.endsWith("/")) webappRoot = webappRoot + "/"; StringBuilder fileUrl = new StringBuilder(); fileUrl.append(serverUrl).append(webappRoot).append("ewui/").append(FileDownloadServlet.SERVLET_NAME).append("?") .append(FileDownloadServlet.PARAM_TYPE).append("="); if (assemblyData!=null) { fileUrl.append(FileDownloadServlet.TYPE_VALUE_ASSEMBLY).append("&").append(FileDownloadServlet.PARAM_ID).append("=").append(jobId) .append("&").append(FileDownloadServlet.PARAM_ASSEMBLY_ID).append("=").append(assemblyData.getId()); } else if (interfData != null) { fileUrl.append(FileDownloadServlet.TYPE_VALUE_INTERFACE).append("&").append(FileDownloadServlet.PARAM_ID).append("=").append(jobId) .append("&").append(FileDownloadServlet.PARAM_INTERFACE_ID).append("=").append(interfData.getInterfaceId()); } else { logger.error("Illegal state. Either assembly or interface data must be not null"); } fileUrl.append("&").append(FileDownloadServlet.PARAM_COORDS_FORMAT).append("=").append(FileDownloadServlet.COORDS_FORMAT_VALUE_CIF); Map<String,Object> page = new HashMap<>(); page.put("title", title); page.put("libURL", nglJsUrl); page.put("jsURL", webappRoot + EPPIC_NGL_JS_FUNCTIONS); page.put("cssUrl", webappRoot + CSSFILE); page.put("fileURL", fileUrl.toString()); page.put("jsVariables", jsVariables); page.put("maxEntropy", String.format("%.4f",maxEntropy)); page.put("size", size); MustacheFactory mf = new DefaultMustacheFactory(); String template = LatticeGUIMustache.expandTemplatePath(TEMPLATE_NGL); Mustache mustache = mf.compile(template); try { mustache.execute(out, page) .flush(); } catch (IOException e) { logger.error("Error generating output from template "+template,e); } } }
JmolPageGenerator { public static void generatePage(String title, String size, String jobId, String serverUrl, String fileName, Interface interfData, Assembly assemblyData, String nglJsUrl, PrintWriter out, String webappRoot) { boolean isCif = true; if (fileName.endsWith("cif")) { isCif = true; } else if (fileName.endsWith("pdb")) { isCif = false; } String jsVariables = generateSelectionVarsNgl(interfData, assemblyData, isCif); double maxEntropy = Math.log(EppicParams.DEF_ENTROPY_ALPHABET.getNumLetters()) / Math.log(2); if (!webappRoot.endsWith("/")) webappRoot = webappRoot + "/"; StringBuilder fileUrl = new StringBuilder(); fileUrl.append(serverUrl).append(webappRoot).append("ewui/").append(FileDownloadServlet.SERVLET_NAME).append("?") .append(FileDownloadServlet.PARAM_TYPE).append("="); if (assemblyData!=null) { fileUrl.append(FileDownloadServlet.TYPE_VALUE_ASSEMBLY).append("&").append(FileDownloadServlet.PARAM_ID).append("=").append(jobId) .append("&").append(FileDownloadServlet.PARAM_ASSEMBLY_ID).append("=").append(assemblyData.getId()); } else if (interfData != null) { fileUrl.append(FileDownloadServlet.TYPE_VALUE_INTERFACE).append("&").append(FileDownloadServlet.PARAM_ID).append("=").append(jobId) .append("&").append(FileDownloadServlet.PARAM_INTERFACE_ID).append("=").append(interfData.getInterfaceId()); } else { logger.error("Illegal state. Either assembly or interface data must be not null"); } fileUrl.append("&").append(FileDownloadServlet.PARAM_COORDS_FORMAT).append("=").append(FileDownloadServlet.COORDS_FORMAT_VALUE_CIF); Map<String,Object> page = new HashMap<>(); page.put("title", title); page.put("libURL", nglJsUrl); page.put("jsURL", webappRoot + EPPIC_NGL_JS_FUNCTIONS); page.put("cssUrl", webappRoot + CSSFILE); page.put("fileURL", fileUrl.toString()); page.put("jsVariables", jsVariables); page.put("maxEntropy", String.format("%.4f",maxEntropy)); page.put("size", size); MustacheFactory mf = new DefaultMustacheFactory(); String template = LatticeGUIMustache.expandTemplatePath(TEMPLATE_NGL); Mustache mustache = mf.compile(template); try { mustache.execute(out, page) .flush(); } catch (IOException e) { logger.error("Error generating output from template "+template,e); } }  }
JmolPageGenerator { public static void generatePage(String title, String size, String jobId, String serverUrl, String fileName, Interface interfData, Assembly assemblyData, String nglJsUrl, PrintWriter out, String webappRoot) { boolean isCif = true; if (fileName.endsWith("cif")) { isCif = true; } else if (fileName.endsWith("pdb")) { isCif = false; } String jsVariables = generateSelectionVarsNgl(interfData, assemblyData, isCif); double maxEntropy = Math.log(EppicParams.DEF_ENTROPY_ALPHABET.getNumLetters()) / Math.log(2); if (!webappRoot.endsWith("/")) webappRoot = webappRoot + "/"; StringBuilder fileUrl = new StringBuilder(); fileUrl.append(serverUrl).append(webappRoot).append("ewui/").append(FileDownloadServlet.SERVLET_NAME).append("?") .append(FileDownloadServlet.PARAM_TYPE).append("="); if (assemblyData!=null) { fileUrl.append(FileDownloadServlet.TYPE_VALUE_ASSEMBLY).append("&").append(FileDownloadServlet.PARAM_ID).append("=").append(jobId) .append("&").append(FileDownloadServlet.PARAM_ASSEMBLY_ID).append("=").append(assemblyData.getId()); } else if (interfData != null) { fileUrl.append(FileDownloadServlet.TYPE_VALUE_INTERFACE).append("&").append(FileDownloadServlet.PARAM_ID).append("=").append(jobId) .append("&").append(FileDownloadServlet.PARAM_INTERFACE_ID).append("=").append(interfData.getInterfaceId()); } else { logger.error("Illegal state. Either assembly or interface data must be not null"); } fileUrl.append("&").append(FileDownloadServlet.PARAM_COORDS_FORMAT).append("=").append(FileDownloadServlet.COORDS_FORMAT_VALUE_CIF); Map<String,Object> page = new HashMap<>(); page.put("title", title); page.put("libURL", nglJsUrl); page.put("jsURL", webappRoot + EPPIC_NGL_JS_FUNCTIONS); page.put("cssUrl", webappRoot + CSSFILE); page.put("fileURL", fileUrl.toString()); page.put("jsVariables", jsVariables); page.put("maxEntropy", String.format("%.4f",maxEntropy)); page.put("size", size); MustacheFactory mf = new DefaultMustacheFactory(); String template = LatticeGUIMustache.expandTemplatePath(TEMPLATE_NGL); Mustache mustache = mf.compile(template); try { mustache.execute(out, page) .flush(); } catch (IOException e) { logger.error("Error generating output from template "+template,e); } }  static void generatePage(String title, String size, String jobId, String serverUrl,
			String fileName, Interface interfData, Assembly assemblyData, String nglJsUrl, PrintWriter out, String webappRoot); }
JmolPageGenerator { public static void generatePage(String title, String size, String jobId, String serverUrl, String fileName, Interface interfData, Assembly assemblyData, String nglJsUrl, PrintWriter out, String webappRoot) { boolean isCif = true; if (fileName.endsWith("cif")) { isCif = true; } else if (fileName.endsWith("pdb")) { isCif = false; } String jsVariables = generateSelectionVarsNgl(interfData, assemblyData, isCif); double maxEntropy = Math.log(EppicParams.DEF_ENTROPY_ALPHABET.getNumLetters()) / Math.log(2); if (!webappRoot.endsWith("/")) webappRoot = webappRoot + "/"; StringBuilder fileUrl = new StringBuilder(); fileUrl.append(serverUrl).append(webappRoot).append("ewui/").append(FileDownloadServlet.SERVLET_NAME).append("?") .append(FileDownloadServlet.PARAM_TYPE).append("="); if (assemblyData!=null) { fileUrl.append(FileDownloadServlet.TYPE_VALUE_ASSEMBLY).append("&").append(FileDownloadServlet.PARAM_ID).append("=").append(jobId) .append("&").append(FileDownloadServlet.PARAM_ASSEMBLY_ID).append("=").append(assemblyData.getId()); } else if (interfData != null) { fileUrl.append(FileDownloadServlet.TYPE_VALUE_INTERFACE).append("&").append(FileDownloadServlet.PARAM_ID).append("=").append(jobId) .append("&").append(FileDownloadServlet.PARAM_INTERFACE_ID).append("=").append(interfData.getInterfaceId()); } else { logger.error("Illegal state. Either assembly or interface data must be not null"); } fileUrl.append("&").append(FileDownloadServlet.PARAM_COORDS_FORMAT).append("=").append(FileDownloadServlet.COORDS_FORMAT_VALUE_CIF); Map<String,Object> page = new HashMap<>(); page.put("title", title); page.put("libURL", nglJsUrl); page.put("jsURL", webappRoot + EPPIC_NGL_JS_FUNCTIONS); page.put("cssUrl", webappRoot + CSSFILE); page.put("fileURL", fileUrl.toString()); page.put("jsVariables", jsVariables); page.put("maxEntropy", String.format("%.4f",maxEntropy)); page.put("size", size); MustacheFactory mf = new DefaultMustacheFactory(); String template = LatticeGUIMustache.expandTemplatePath(TEMPLATE_NGL); Mustache mustache = mf.compile(template); try { mustache.execute(out, page) .flush(); } catch (IOException e) { logger.error("Error generating output from template "+template,e); } }  static void generatePage(String title, String size, String jobId, String serverUrl,
			String fileName, Interface interfData, Assembly assemblyData, String nglJsUrl, PrintWriter out, String webappRoot);  }