summaryrefslogtreecommitdiff
path: root/noncore/apps/oxygen/kmolelements.h
authorcniehaus <cniehaus>2002-09-15 17:09:54 (UTC)
committer cniehaus <cniehaus>2002-09-15 17:09:54 (UTC)
commit33ec9ead7ce30bf9450b9048506f0bda49ba4791 (patch) (side-by-side diff)
tree1683b16a3cb06d7773427193fc4ea5284bf3bdaa /noncore/apps/oxygen/kmolelements.h
parent7a8dc6b0a16db160a1e50fde8f298eb9e3cb0099 (diff)
downloadopie-33ec9ead7ce30bf9450b9048506f0bda49ba4791.zip
opie-33ec9ead7ce30bf9450b9048506f0bda49ba4791.tar.gz
opie-33ec9ead7ce30bf9450b9048506f0bda49ba4791.tar.bz2
Fell free to shoot me if I messed up CVS again... *fingercrossed*
Diffstat (limited to 'noncore/apps/oxygen/kmolelements.h') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/oxygen/kmolelements.h161
1 files changed, 161 insertions, 0 deletions
diff --git a/noncore/apps/oxygen/kmolelements.h b/noncore/apps/oxygen/kmolelements.h
new file mode 100644
index 0000000..06d1469
--- a/dev/null
+++ b/noncore/apps/oxygen/kmolelements.h
@@ -0,0 +1,161 @@
+/*
+ * kmolelements.h
+ *
+ * Copyright (C) 2000 Tomislav Gountchev <tomi@idiom.com>
+ */
+
+// classes that store and manipulate chemical formulas represented as
+// lists of elements
+
+#ifndef KMOLELEMENTS_H
+#define KMOLELEMENTS_H
+
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+
+#include <qlist.h>
+#include <qdict.h>
+#include <qstring.h>
+#include <qtextstream.h>
+
+class ElementCoef;
+class ElementList;
+
+/**
+ * A generic chemical entity. Can be an element or a group.
+ */
+class SubUnit {
+ public:
+
+ SubUnit();
+
+ virtual ~SubUnit();
+
+ /**
+ * Construct a subunit and return a pointer to it. The syntax of LINE is
+ * the one used in the element definition file.
+ */
+ static SubUnit* makeSubUnit(QString line);
+
+ /**
+ * Get the molecular weight of THIS, based on the data from ELSTABLE.
+ */
+ virtual double getWeight(QDict<SubUnit>* elstable) const;
+
+ /**
+ * Add THIS to ELS.
+ */
+ virtual void addTo(ElementList& els, double coef) = 0;
+
+ virtual QString getName() const;
+
+ /**
+ * Write THIS to LINE, in the format used in the definition file.
+ */
+ virtual void writeOut(QString& line) = 0;
+};
+
+
+/**
+ * A group of elements.
+ */
+class ElementList : public SubUnit {
+ public:
+ ElementList ();
+ ElementList (QString name);
+ virtual ~ElementList();
+ double getWeight(QDict<SubUnit>* elstable) const;
+
+ /**
+ * Return a string representing the elemental composition of THIS, as
+ * a tab-separated element - percentage pairs, separated by newlines.
+ */
+ QString getEA(QDict<SubUnit>* elstable, double mw = 0) const;
+
+ /**
+ * Return a string representing THIS as an empirical chemical formula.
+ */
+ QString getEmpFormula() const;
+
+ /**
+ * Multiply THIS (i.e. the coefficient of each element) by coef.
+ */
+ void multiplyBy(double coef);
+
+ /**
+ * Add THIS to ELS. THIS is not modified; ELS is.
+ */
+ void addTo(ElementList& els, double coef);
+
+ /**
+ * Add an element to THIS, with a coefficient COEF.
+ */
+ void addElement(const QString& name, double coef);
+
+ /**
+ * True iff THIS contains element named NAME.
+ */
+ bool contains(const QString& name);
+
+
+ bool isEmpty();
+
+ /**
+ * The name of THIS, as a chemical group.
+ */
+ QString getName() const;
+
+ /**
+ * Write THIS to LINE, in a format suitable for the element definition file.
+ */
+ void writeOut(QString& line);
+
+ private:
+ QString name;
+ QList<ElementCoef>* elements;
+};
+
+/**
+ * A chemical element.
+ */
+class Element : public SubUnit {
+ public:
+ Element(const QString& name, double weight);
+ virtual ~Element();
+ double getWeight(QDict<SubUnit>* elstable) const;
+
+ /**
+ * Add THIS to ELS, with a coefficient COEF.
+ */
+ void addTo(ElementList& els, double coef);
+
+ QString getName() const;
+
+ void writeOut(QString& line);
+
+ private:
+ double weight;
+ QString name;
+};
+
+
+/**
+ * An element - coefficient pair. Used to represent elements within an
+ * element list.
+ */
+class ElementCoef {
+ friend class ElementList;
+ public:
+ ElementCoef(const QString& name, double coef = 1.0);
+ private:
+ QString name;
+ double coef;
+};
+
+
+#endif
+
+