1
/* $Revision: 7981 $ $Author: egonw $ $Date: 2007-02-20 18:05:37 +0100 (Tue, 20 Feb 2007) $
3
* Copyright (C) 1997-2007 Egon Willighagen <egonw@users.sf.net>
5
* Contact: cdk-devel@lists.sourceforge.net
7
* This program is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU Lesser General Public License
9
* as published by the Free Software Foundation; either version 2.1
10
* of the License, or (at your option) any later version.
11
* All we ask is that proper credit is given for our work, which includes
12
* - but is not limited to - adding the above copyright notice to the beginning
13
* of your source code files, and to any copyright notice that you may distribute
14
* with programs based on this work.
16
* This program is distributed in the hope that it will be useful,
17
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
* GNU Lesser General Public License for more details.
21
* You should have received a copy of the GNU Lesser General Public License
22
* along with this program; if not, write to the Free Software
23
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
26
package org.openscience.cdk.io.cml;
28
import org.openscience.cdk.interfaces.IChemFile;
29
import org.openscience.cdk.tools.LoggingTool;
30
import org.xml.sax.Attributes;
33
* @author Egon Willighagen <egonw@sci.kun.nl>
37
public class JMOLANIMATIONConvention extends CMLCoreModule {
39
private final int UNKNOWN = -1;
40
private final int ENERGY = 1;
43
private String frame_energy;
44
private LoggingTool logger;
46
public JMOLANIMATIONConvention(IChemFile chemFile) {
48
logger = new LoggingTool(this);
52
public JMOLANIMATIONConvention(ICMLModule conv) {
54
logger = new LoggingTool(this);
57
public void startElement(CMLStack xpath, String uri, String local, String raw, Attributes atts) {
59
if (name.equals("list")) {
60
logger.debug("Oke, JMOLANIMATION seems to be kicked in :)");
61
// cdo.startObject("Animation");
62
currentChemSequence = currentChemFile.getBuilder().newChemSequence();
63
super.startElement(xpath, uri, local, raw, atts);
64
} else if (name.equals("molecule")) {
65
// cdo.startObject("Frame");
66
currentChemModel = currentChemFile.getBuilder().newChemModel();
67
logger.debug("New frame being parsed.");
68
super.startElement(xpath, uri, local, raw, atts);
69
} else if (name.equals("float")) {
70
boolean isEnergy = false;
71
logger.debug("FLOAT found!");
72
for (int i = 0; i < atts.getLength(); i++) {
73
logger.debug(" att: ", atts.getQName(i), " -> ", atts.getValue(i));
74
if (atts.getQName(i).equals("title")
75
&& atts.getValue(i).equals("FRAME_ENERGY")) {
80
// oke, this is the frames energy!
83
super.startElement(xpath, uri, local, raw, atts);
86
super.startElement(xpath, uri, local, raw, atts);
90
public void endElement(CMLStack xpath, String uri, String local, String raw) {
92
if (current == ENERGY) {
93
// cdo.setObjectProperty("Frame", "energy", frame_energy);
95
// FIXME: does not have a ChemFileCDO equivalent
98
} else if (name.equals("list")) {
99
super.endElement(xpath, uri, local, raw);
100
// cdo.endObject("Animation");
101
currentChemFile.addChemSequence(currentChemSequence);
102
} else if (name.equals("molecule")) {
103
super.endElement(xpath, uri, local, raw);
104
// cdo.endObject("Frame");
105
// nothing done in the CD upon this event
107
super.endElement(xpath, uri, local, raw);
111
public void characterData(CMLStack xpath, char ch[], int start, int length) {
112
if (current == ENERGY) {
113
frame_energy = new String(ch, start, length);
115
super.characterData(xpath, ch, start, length);