⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jchempaintabstractapplet.java

📁 化学图形处理软件
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
		/**	 * loads a molecule from url or smiles	 */	protected void loadModelFromParam() {		URL fileURL = null;		String smiles=null;		try {			URL documentBase = getDocumentBase();			String load = getParameter("load");			if (load != null)				fileURL = new URL(documentBase, load);			smiles = getParameter("smiles");			} catch (Exception exception) {			System.out.println("Cannot load model: " + exception.toString());			exception.printStackTrace();		}		loadModelFromUrl(fileURL);		if(smiles!=null)			loadModelFromSmiles(smiles);	}		/**	 * Loads a molecule from a smiles into jcp	 * 	 * @param fileURL	 */	public void loadModelFromSmiles(String smiles) {		if (smiles != null) {			try {				SmilesParser sp=new SmilesParser(DefaultChemObjectBuilder.getInstance());				IMolecule mol = sp.parseSmiles(smiles);				StructureDiagramGenerator sdg = new StructureDiagramGenerator();				sdg.setMolecule(mol);				sdg.generateCoordinates(new Vector2d(0, 1));				mol=sdg.getMolecule();				IChemModel chemModel = DefaultChemObjectBuilder.getInstance().newChemModel();				chemModel.setMoleculeSet(DefaultChemObjectBuilder.getInstance().newMoleculeSet());				chemModel.getMoleculeSet().addAtomContainer(mol);				theModel = new JChemPaintModel(chemModel);			} catch (Exception exception) {				System.out.println("Cannot parse model: " + exception.toString());				exception.printStackTrace();			}		}else{			theModel=new JChemPaintModel();		}		initPanelAndModel(theJcpp);	}	/**	 * Loads a molecule from a url into jcp	 * 	 * @param fileURL	 */	public void loadModelFromUrl(URL fileURL) {		if (fileURL != null) {			try {				InputStreamReader isReader = new InputStreamReader(fileURL.openStream());				IChemObjectReader reader = new ReaderFactory().createReader(isReader);				ChemModel chemModel = (ChemModel) reader.read(new ChemModel());        				int count=0;				for(int i=0;i<chemModel.getMoleculeSet().getMoleculeCount();i++){					for(int k=0;k<chemModel.getMoleculeSet().getMolecule(i).getAtomCount();k++){						chemModel.getMoleculeSet().getMolecule(i).getAtom(k).setProperty("OriginalNumber", new Integer(count));						count++;					}				}				theModel = new JChemPaintModel(chemModel);			} catch (Exception exception) {				System.out.println("Cannot parse model: " + exception.toString());				exception.printStackTrace();			}		}else{			theModel=new JChemPaintModel();		}		initPanelAndModel(theJcpp);	}		public void start() {		//Parameter parsing goes here		loadModelFromParam();		String atomNumbers=getParameter("atomNumbersVisible");		if(atomNumbers!=null){			if(atomNumbers.equals("true"))				theJcpp.getJChemPaintModel().getRendererModel().setDrawNumbers(true);		}		String background = getParameter("background");		if(background!=null){			theJcpp.getJChemPaintModel().getRendererModel().setBackColor(new Color(Integer.parseInt(background)));		}	}		public void init(){		prepareExternalFrame();	}	public void stop() {	}	/**	 * @return Returns the theJcpp.	 */	public JChemPaintPanel getTheJcpp() {		return theJcpp;	}	/**	 * @param theJcpp The theJcpp to set.	 */	public void setTheJcpp(JChemPaintPanel theJcpp) {		this.theJcpp = theJcpp;	}    public void setTheModel(JChemPaintModel theModel){    this.theModel=theModel;  }    public String getMolFile() throws Exception{    StringWriter sw = new StringWriter();    MDLWriter mdlwriter = new MDLWriter(sw);    mdlwriter.dontWriteAromatic();    mdlwriter.write(theJcpp.getJChemPaintModel().getChemModel());    return(sw.toString());  }      public String getSmiles(){		ChemModel model = (ChemModel) theJcpp.getJChemPaintModel().getChemModel();        SmilesGenerator generator = new SmilesGenerator();		Iterator containers = ChemModelManipulator.getAllAtomContainers(model).iterator();		String SMILES = "";		while (containers.hasNext()) {			IMolecule molecule = model.getBuilder().newMolecule((IAtomContainer)containers.next());			SMILES += generator.createSMILES(molecule);			if (containers.hasNext()) SMILES += ".";		}		return SMILES;  }    public String getSmilesChiral() throws Exception{		ChemModel model = (ChemModel) theJcpp.getJChemPaintModel().getChemModel();        Iterator containers = ChemModelManipulator.getAllAtomContainers(model).iterator();		String SMILES = "";		while (containers.hasNext()) {			IAtomContainer container = (IAtomContainer)containers.next();			IMolecule moleculewithh = model.getBuilder().newMolecule(container);			new HydrogenAdder().addExplicitHydrogensToSatisfyValency(moleculewithh);			double bondLength = GeometryTools.getBondLengthAverage(container,theJcpp.getJChemPaintModel().getRendererModel().getRenderingCoordinates());			new HydrogenPlacer().placeHydrogens2D(moleculewithh, bondLength);			boolean[] bool=new boolean[moleculewithh.getBondCount()];			SmilesGenerator sg = new SmilesGenerator();			for(int i=0;i<bool.length;i++){				if (sg.isValidDoubleBondConfiguration(moleculewithh, moleculewithh.getBond(i)))					bool[i]=true;			}			SMILES += sg.createSMILES(moleculewithh);			if (containers.hasNext()) SMILES += ".";		}		return SMILES;  }  /**   * This method sets a structure in the editor and leaves the old one.   * This method replaces all \n characters with the system line separator. This can be used when setting a mol file in an applet   * without knowing which platform the applet is running on.   *    * @param mol The mol file to set (V2000)   * @throws Exception   */  public void addMolFileWithReplace(String mol) throws Exception{	StringBuffer newmol=new StringBuffer();    int s = 0;    int e = 0;    while ((e = mol.indexOf("\\n", s)) >= 0) {      newmol.append(mol.substring(s, e));      newmol.append(System.getProperty("file.separator"));      s = e + 1;    }    newmol.append(mol.substring(s));    MDLV2000Reader reader=new MDLV2000Reader(new StringReader(newmol.toString()));    IMolecule cdkmol=(IMolecule)reader.read(DefaultChemObjectBuilder.getInstance().newMolecule());    new InsertTextPanel(theJcpp,null).generateModel(cdkmol);    repaint();  }  /**   * This method sets a new structure in the editor and removes the old one.   * This method replaces all \n characters with the system line separator. This can be used when setting a mol file in an applet   * without knowing which platform the applet is running on.   *    * @param mol The mol file to set   * @throws Exception   */  public void setMolFileWithReplace(String mol) throws Exception{	StringBuffer newmol=new StringBuffer();    int s = 0;    int e = 0;    while ((e = mol.indexOf("\\n", s)) >= 0) {      newmol.append(mol.substring(s, e));      newmol.append(System.getProperty("file.separator"));      s = e + 1;    }    newmol.append(mol.substring(s));    theJcpp.showChemFile(new StringReader(newmol.toString()));    repaint();  }    public void setMolFile(String mol) throws Exception{    theJcpp.showChemFile(new StringReader(mol));    repaint();  }    public void clear() throws Exception{	  theModel.getChemModel().setMoleculeSet(new MoleculeSet());	  repaint();  }  public void selectAtom(int atom){    theJcpp.getJChemPaintModel().getRendererModel().setExternalHighlightColor(Color.RED);    IAtomContainer ac=theJcpp.getJChemPaintModel().getChemModel().getMoleculeSet().getBuilder().newAtomContainer();    ac.addAtom(theJcpp.getJChemPaintModel().getChemModel().getMoleculeSet().getMolecule(0).getAtom(atom));    theJcpp.getJChemPaintModel().getRendererModel().setExternalSelectedPart(ac);    getTheJcpp().repaint();  }	/**	 * @return Returns the jexf.	 */	private JExternalFrame getJexf() {		if (jexf == null)			jexf = new JExternalFrame();		return jexf;	}	/**	 * sets title for external frame	 * adds listener for double clicks in order to open external frame	 */	private void prepareExternalFrame() { 		if (this.getParameter("name") != null)			getJexf().setTitle(this.getParameter("name"));		getTheJcpp().getDrawingPanel().addMouseListener(new MouseAdapter() {			public void mousePressed(MouseEvent e) {				if (e.getButton() == 1 && e.getClickCount() == 2)					if (!getJexf().isShowing()) {						getJexf().show(getTheJcpp());				}				}		});	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -