summaryrefslogtreecommitdiff
path: root/noncore/apps/oxygen/kmolcalc.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/kmolcalc.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/kmolcalc.h') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/oxygen/kmolcalc.h110
1 files changed, 110 insertions, 0 deletions
diff --git a/noncore/apps/oxygen/kmolcalc.h b/noncore/apps/oxygen/kmolcalc.h
new file mode 100644
index 0000000..c3e02f3
--- a/dev/null
+++ b/noncore/apps/oxygen/kmolcalc.h
@@ -0,0 +1,110 @@
+/*
+ * kmolcalc.h
+ *
+ * Copyright (C) 2000 Tomislav Gountchev <tomi@idiom.com>
+ */
+
+
+#ifndef KMOLCALC_H
+#define KMOLCALC_H
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+
+#include "kmolelements.h"
+#include <qdict.h>
+#include <qlist.h>
+#include <qstring.h>
+#include <qfile.h>
+#include <qfileinfo.h>
+#include <qmessagebox.h>
+#include <qtextstream.h>
+
+
+/**
+ * KMOLCALC is the calculation engine. It knows about a hashtable of user defined atomic
+ * weights and group definitions ELSTABLE, and the currently processed formula, stored
+ * as a list of elements and their coefficients, ELEMENTS.
+ */
+class KMolCalc {
+
+public:
+
+ KMolCalc();
+ ~KMolCalc();
+
+ /**
+ * Parse a string S and construct the ElementList ELEMENTS, representing the composition
+ * of S. Returns "OK" if successful, or an error message if parsing failed.
+ * The elements is S must be valid element or group symbols, as stored in ELSTABLE.
+ * See help files for correct formula syntax.
+ */
+ QString readFormula(const QString& s);
+
+ /**
+ * Calculate and return the molecular weight of the current chemical formula.
+ */
+ double getWeight();
+
+ /**
+ * Return the elemental composition of the current formula, as a string of tab-separated
+ * element - percentage pairs, separated by newlines.
+ */
+ QString getEA();
+
+
+ /**
+ * Return the empirical formula of the current compound as a QString.
+ */
+ QString getEmpFormula();
+
+ /**
+ * Add a new element name - atomic weight record to the ELSTABLE hashtable.
+ * Assumes NAME has valid syntax.
+ */
+ void defineElement(const QString& name, double weight);
+
+ /**
+ * Add a new group definition to the ELSTABLE. Returns "OK" if OK, error message
+ * if parsing FORMULA fails. Assumes the syntax of NAME is correct.
+ */
+ QString defineGroup(const QString& name, const QString& formula);
+
+ /**
+ * Remove a group or element definition from ELSTABLE.
+ */
+ void undefineGroup(const QString& name);
+
+ /**
+ * Save the element definitions file.
+ */
+ void writeElstable();
+
+ /**
+ * Read the element definitions file and construct ELSTABLE.
+ */
+ void readElstable();
+
+ /**
+ * The element dictionary.
+ */
+ QDict<SubUnit>* elstable;
+
+ QString mwfile;
+
+ private:
+ double weight;
+
+ QString readGroup(const QString& s, ElementList* els);
+ void readMwfile(QFile& f);
+ ElementList* elements;
+};
+
+#endif
+
+
+
+
+