* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
#include "cmlclasses.h"
-#include <kdebug.h>
+
using namespace CML;
-Molecule::Molecule()
+#include <QDebug>
+
+Molecule::Molecule(){}
+
+QString Molecule::debug()
{
+ qDebug() << "Molecule " << m_id;
+ foreach( CML::Atom* a, m_atoms )
+ qDebug() << a->debug();
+ foreach( CML::Bond* b, m_bonds )
+ qDebug() << b->debug();
}
Atom::Atom()
namespace CML
{
+
+class Atom;
+class Bond;
class EDUSCIENCE_EXPORT Molecule
{
public:
Molecule();
+ void setAtoms( QList<CML::Atom*> list ){
+ m_atoms = list;
+ }
+
+ void setBonds( QList<CML::Bond*> list ){
+ m_bonds = list;
+ }
+
+ void setID( const QString& id ){
+ m_id = id;
+ }
+
+ QString debug();
+
+ private:
+ QList<CML::Atom*> m_atoms;
+ QList<CML::Bond*> m_bonds;
+
+ QString m_id;
};
class EDUSCIENCE_EXPORT Atom
--- /dev/null
+<?xml version="1.0"?>
+<molecule xmlns="http://www.xml-cml.org/schema/cml2/core" id="2-Propan-2-yloxypropane">
+ <atomArray>
+ <atom id="a1" elementType="H" x3="-2.015900" y3="-0.043200" z3="-0.891400"/>
+ <atom id="a2" elementType="C" x3="-2.487000" y3="-0.089500" z3="-1.877800"/>
+ <atom id="a3" elementType="H" x3="-2.086500" y3="0.722700" z3="-2.492800"/>
+ <atom id="a4" elementType="H" x3="-2.178100" y3="-1.022200" z3="-2.357200"/>
+ <atom id="a5" elementType="C" x3="-4.007200" y3="0.002000" z3="-1.772300"/>
+ <atom id="a6" elementType="H" x3="-4.393900" y3="-0.852900" z3="-1.207900"/>
+ <atom id="a7" elementType="C" x3="-4.414600" y3="1.281600" z3="-1.055800"/>
+ <atom id="a8" elementType="H" x3="-4.007200" y3="1.320200" z3="-0.040900"/>
+ <atom id="a9" elementType="H" x3="-4.075100" y3="2.167200" z3="-1.602900"/>
+ <atom id="a10" elementType="H" x3="-5.504700" y3="1.353300" z3="-0.993200"/>
+ <atom id="a11" elementType="O" x3="-4.588300" y3="0.043500" z3="-3.090000"/>
+ <atom id="a12" elementType="C" x3="-4.971100" y3="-1.241800" z3="-3.616500"/>
+ <atom id="a13" elementType="H" x3="-4.344600" y3="-2.034000" z3="-3.193300"/>
+ <atom id="a14" elementType="C" x3="-6.439200" y3="-1.515700" z3="-3.299800"/>
+ <atom id="a15" elementType="H" x3="-6.608700" y3="-1.568400" z3="-2.221000"/>
+ <atom id="a16" elementType="H" x3="-7.078600" y3="-0.710400" z3="-3.675000"/>
+ <atom id="a17" elementType="H" x3="-6.772500" y3="-2.459700" z3="-3.741100"/>
+ <atom id="a18" elementType="C" x3="-4.750200" y3="-1.199300" z3="-5.121800"/>
+ <atom id="a19" elementType="H" x3="-5.334900" y3="-0.398200" z3="-5.585500"/>
+ <atom id="a20" elementType="H" x3="-3.700200" y3="-0.989300" z3="-5.347800"/>
+ <atom id="a21" elementType="H" x3="-5.022000" y3="-2.148100" z3="-5.594500"/>
+ </atomArray>
+ <bondArray>
+ <bond atomRefs2="a1 a2" order="1"/>
+ <bond atomRefs2="a2 a3" order="1"/>
+ <bond atomRefs2="a2 a4" order="1"/>
+ <bond atomRefs2="a2 a5" order="1"/>
+ <bond atomRefs2="a5 a6" order="1"/>
+ <bond atomRefs2="a5 a7" order="1"/>
+ <bond atomRefs2="a5 a11" order="1"/>
+ <bond atomRefs2="a7 a8" order="1"/>
+ <bond atomRefs2="a7 a9" order="1"/>
+ <bond atomRefs2="a7 a10" order="1"/>
+ <bond atomRefs2="a11 a12" order="1"/>
+ <bond atomRefs2="a12 a13" order="1"/>
+ <bond atomRefs2="a12 a14" order="1"/>
+ <bond atomRefs2="a12 a18" order="1"/>
+ <bond atomRefs2="a14 a15" order="1"/>
+ <bond atomRefs2="a14 a16" order="1"/>
+ <bond atomRefs2="a14 a17" order="1"/>
+ <bond atomRefs2="a18 a19" order="1"/>
+ <bond atomRefs2="a18 a20" order="1"/>
+ <bond atomRefs2="a18 a21" order="1"/>
+ </bondArray>
+</molecule>
xmlReader.setContentHandler( handler );
xmlReader.parse( source );
- QList<CML::Atom*> parsedAtoms;
- parsedAtoms = handler->getAtoms();
- QList<CML::Bond*> parsedBonds;
- parsedBonds = handler->getBonds();
-
- kDebug() << "Found " << parsedAtoms.count() << " Atoms and " << parsedBonds.count() << " Bonds!" << endl;
-
- foreach( CML::Atom* a, parsedAtoms )
- kDebug() << a->debug() << endl;
- foreach( CML::Bond* b, parsedBonds )
- kDebug() << b->debug() << endl;
+ CML::Molecule * mol = handler->getMolecule();
+ kDebug() << mol->debug() << endl;
return 0;
}
const QString& qName,
const QXmlAttributes& attr )
{
- if ( qName.toUpper() == "ATOM" ) {
+ if ( qName.toUpper() == "MOLECULE" ) {
+ tmp_molecule = new CML::Molecule();
+
+ tmp_molecule->setID( attr.value( "id" ) );
+ }
+ else if ( qName.toUpper() == "ATOM" ) {
tmp_atom = new CML::Atom();
QString x2 = attr.value( "x2");
bool CMLParser::endElement( const QString&, const QString&,
const QString& qName )
{
- if ( qName.toUpper() == "ATOM" ) {
+ if ( qName.toUpper() == "MOLECULE" ) {
+ tmp_molecule->setAtoms( getAtoms() );
+ tmp_molecule->setBonds( getBonds() );
+ }
+ else if ( qName.toUpper() == "ATOM" ) {
localAtoms.append( tmp_atom );
tmp_atom = 0;
}
- if ( qName.toUpper() == "BOND" ) {
+ else if ( qName.toUpper() == "BOND" ) {
localBonds.append( tmp_bond );
tmp_bond = 0;
}
QList<CML::Atom*> getAtoms();
QList<CML::Bond*> getBonds();
+
+ CML::Molecule* getMolecule(){
+ return tmp_molecule;
+ }
private:
QList<CML::Atom*> localAtoms;
QList<CML::Bond*> localBonds;
CML::Bond *tmp_bond;
+
+ CML::Molecule *tmp_molecule;
CML::Atom * tmp_atom;
};