chemicaldataobject.cpp
moleculeparser.cpp
parser.cpp
- xml_cml.cpp
- cmlclasses.cpp
)
kde4_automoc(${science_LIB_SRCS})
+++ /dev/null
-/***************************************************************************
- * Copyright (C) 2006 by Carsten Niehaus *
- * cniehaus@kde.org *
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program; if not, write to the *
- * Free Software Foundation, Inc., *
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
- ***************************************************************************/
-#include "cmlclasses.h"
-
-using namespace CML;
-
-#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()
-{
- m_elementType = QString( "" );
- m_id = QString( "" );
- coord_x2 = 0.0;
- coord_x3 = 0.0;
- coord_y2 = 0.0;
- coord_y3 = 0.0;
- coord_z3 = 0.0;
-}
-
-Bond::Bond()
-{
-}
+++ /dev/null
-#ifndef CMLCLASSES_H
-#define CMLCLASSES_H
-/***************************************************************************
- * Copyright (C) 2006 by Carsten Niehaus *
- * cniehaus@kde.org *
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program; if not, write to the *
- * Free Software Foundation, Inc., *
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
- ***************************************************************************/
-
-#include <libkdeedu_science_export.h>
-
-#include <QString>
-#include <QList>
-
-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
-{
- public:
- Atom( );
-
- QString debug(){
- QString db = "ID: " + m_id + " Type: " + m_elementType + " Coordinates: " + "x3: " + QString::number( coord_x3 ) + " y3: " + QString::number( coord_y3 )+ " z3:" + QString::number( coord_z3 ) + "\n";
- return db;
- }
-
- void setID( const QString& id ){
- m_id = id;
- }
-
- void setElementType( const QString& et ){
- m_elementType = et;
- }
-
- void setX2( double i ){
- coord_x2 = i;
- }
-
- void setX3( double i ){
- coord_x3 = i;
- }
-
- void setY2( double i ){
- coord_y2 = i;
- }
-
- void setY3( double i ){
- coord_y3 = i;
- }
-
- void setZ3( double i ){
- coord_z3 = i;
- }
-
- QString id() const{
- return m_id;
- }
-
- private:
- QString m_elementType;
- QString m_id;
-
- //we need to store five possible coordinates, 2 for 2d, 3 for 3d
- double coord_x2, coord_x3,
- coord_y2, coord_y3,
- coord_z3;
-};
-
-class EDUSCIENCE_EXPORT Bond
-{
- public:
- Bond();
-
- QString debug(){
- QString db = "Atom 1: " + m_startatom_id + " ... Atom 2: " + m_endatom_id;
- return db;
- }
-
-
- /**
- * defines the two Atoms which start and stop the bond
- */
- void setAtoms( const QString& id1, const QString& id2 ){
- m_startatom_id = id1;
- m_endatom_id = id2;
- }
-
- void setOrder( int o ){
- m_order = o;
- }
-
- private:
- QString m_startatom_id;
- QString m_endatom_id;
-
- int m_order;
-};
-
-}
-#endif // CMLCLASSES_H
+++ /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>
#target_link_libraries(isotopereadingtest ${KDE4_KDECORE_LIBS} science )
-########### next target ###############
-
-set(cml2test_SRCS cml2test.cpp )
-
-kde4_automoc(${cml2test_SRCS})
-
-kde4_add_executable(cml2test ${cml2test_SRCS})
-
-target_link_libraries(cml2test ${KDE4_KDECORE_LIBS} science )
-
-
endif(KDE4_BUILD_TESTS)
+++ /dev/null
-#include <kdebug.h>
-#include <iostream>
-
-#include <QTextStream>
-#include <QFile>
-#include <QDateTime>
-#include <qxml.h>
-
-#include "../xml_cml.h"
-#include "../cmlclasses.h"
-
-int main(int argc, char *argv[])
-{
- if (argc < 2 || argc > 2) {
- std::cout << "Usage: elements <XML_FILE>\n";
- return 1;
- }
-
- CMLParser *handler = new CMLParser();
-
- QFile xmlFile(argv[1]);
-
- if ( !xmlFile.open( IO_ReadOnly ) )
- return false;
-
- QXmlInputSource source( &xmlFile );
- QXmlSimpleReader xmlReader;
- xmlReader.setContentHandler( handler );
- xmlReader.parse( source );
-
- CML::Molecule * mol = handler->getMolecule();
- kDebug() << mol->debug() << endl;
-
- return 0;
-}
+++ /dev/null
-<?xml version="1.0"?>
-<molecule xmlns="http://www.xml-cml.org/schema/cml2/core" id="Ethanol">
- <atomArray>
- <atom id="a1" elementType="H" x3="-1.916300" y3="-0.043300" z3="-1.055200"/>
- <atom id="a2" elementType="C" x3="-2.529600" y3="-0.050300" z3="-1.960600"/>
- <atom id="a3" elementType="H" x3="-2.235900" y3="0.793700" z3="-2.591800"/>
- <atom id="a4" elementType="H" x3="-2.311100" y3="-0.960600" z3="-2.527100"/>
- <atom id="a5" elementType="C" x3="-4.003000" y3="0.025300" z3="-1.617800"/>
- <atom id="a6" elementType="H" x3="-4.299600" y3="-0.832200" z3="-1.006300"/>
- <atom id="a7" elementType="H" x3="-4.224400" y3="0.947100" z3="-1.071600"/>
- <atom id="a8" elementType="O" x3="-4.760100" y3="0.012900" z3="-2.821500"/>
- <atom id="a9" elementType="H" x3="-5.698200" y3="0.061600" z3="-2.569500"/>
- </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 a8" order="1"/>
- <bond atomRefs2="a8 a9" order="1"/>
- </bondArray>
-</molecule>
+++ /dev/null
-/****************************************************************************
- * ** Copyright ( C ) 1992-2000 Trolltech AS. All rights reserved.
- * ** Copyright ( C ) 2006 Carsten Niehaus <cniehaus@kde.org>
- * **
- * ** This file is part of an example program for Qt. This example
- * ** program may be used, distributed and modified without limitation.
- * **
- * *****************************************************************************/
-
-#include "xml_cml.h"
-
-#include <QFile>
-#include <QString>
-
-#include <QtDebug>
-
-CMLParser::CMLParser()
- : QXmlDefaultHandler()
-{
-}
-
-CMLParser::~CMLParser()
-{
-}
-
-bool CMLParser::startDocument()
-{
- return TRUE;
-}
-
-bool CMLParser::startElement( const QString&, const QString&,
- const QString& qName,
- const QXmlAttributes& attr )
-{
- 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");
- if ( x2 != QString( "" ) )
- tmp_atom->setX2( x2.toDouble() );
-
- QString x3 = attr.value( "x3");
- if ( x3 != QString( "" ) )
- tmp_atom->setX3( x3.toDouble() );
-
- QString y2 = attr.value( "y2");
- if ( y2 != QString( "" ) )
- tmp_atom->setY2( y2.toDouble() );
-
- QString y3 = attr.value( "y3");
- if ( y3 != QString( "" ) )
- tmp_atom->setY3( y3.toDouble() );
-
- QString z3 = attr.value( "z3");
- if ( z3 != QString( "" ) )
- tmp_atom->setZ3( z3.toDouble() );
-
- tmp_atom->setID( attr.value( "id" ) );
- }
- else if ( qName.toUpper() == "BOND" ) {
- tmp_bond = new CML::Bond();
-
- QString order = attr.value( "order");
- if ( order != QString( "" ) )
- tmp_bond->setOrder( order.toInt() );
-
- QString atomRef = attr.value( "atomRefs2");
- if ( atomRef != QString( "" ) )
- {
- QStringList Split = atomRef.split( " " );
- tmp_bond->setAtoms( Split.at( 0 ), Split.at( 1 ) );
- }
- }
- return TRUE;
-}
-
-bool CMLParser::endElement( const QString&, const QString&,
- const QString& qName )
-{
- if ( qName.toUpper() == "MOLECULE" ) {
- tmp_molecule->setAtoms( getAtoms() );
- tmp_molecule->setBonds( getBonds() );
- }
- else if ( qName.toUpper() == "ATOM" ) {
- localAtoms.append( tmp_atom );
- tmp_atom = 0;
- }
- else if ( qName.toUpper() == "BOND" ) {
- localBonds.append( tmp_bond );
- tmp_bond = 0;
- }
- return TRUE;
-}
-
-bool CMLParser::characters( const QString &ch )
-{
- return TRUE;
-}
-
-bool CMLParser::ignorableWhitespace( const QString &ch )
-{
- return TRUE;
-}
-
-QList<CML::Atom*> CMLParser::getAtoms()
-{
- return localAtoms;
-}
-
-QList<CML::Bond*> CMLParser::getBonds()
-{
- return localBonds;
-}
+++ /dev/null
-/****************************************************************************
- * ** $Id: xml_cml.h,v 1.2 2002/07/21 23:27:05 atenderholt Exp $
- * **
- * ** Copyright ( C ) 1992-2000 Trolltech AS. All rights reserved.
- * **
- * ** This file is part of an example program for Qt. This example
- * ** program may be used, distributed and modified without limitation.
- * **
- * *****************************************************************************/
-
-#ifndef XML_CML_H
-#define XML_CML_H
-
-#include <libkdeedu_science_export.h>
-
-#include <qxml.h>
-#include <QList>
-
-#include "cmlclasses.h"
-
-class QString;
-
-// possible states (CMLParser::states)
-// set in defs.h
-//X #define CML_NONE 0
-//X #define CML_ATOM 1
-//X #define CML_BOND 2
-//X #define CML_MOLECULE 10
-//X #define CML_NONE 1
-//X #define CML_ATOM 2
-//X #define CML_BOND 3
-//X #define CML_ATOMARRAY 4
-//X #define CML_BONDARRAY 5
-
-
-class EDUSCIENCE_EXPORT CMLParser : public QXmlDefaultHandler
-{
- public:
- CMLParser();
- virtual ~CMLParser();
-
- bool startDocument();
-
- bool startElement( const QString&,
- const QString&,
- const QString& ,
- const QXmlAttributes& );
-
- bool endElement( const QString&, const QString&, const QString& );
-
- bool characters( const QString& );
-
- bool ignorableWhitespace( const QString& );
-
- 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;
-};
-
-#endif