summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Luevano <55825613+luevano@users.noreply.github.com>2020-02-20 19:54:46 -0700
committerDavid Luevano <55825613+luevano@users.noreply.github.com>2020-02-20 19:54:46 -0700
commit7a83a6e48a7503848bf1a4abd448f7858dca71e0 (patch)
treeb887c9491672a82630723088e5f8878b69377dde
parent0c91ee8b6c968457cff1d968cf69add73902bd11 (diff)
Add basic compound object
-rw-r--r--ml_exp/__main__.py8
-rw-r--r--ml_exp/compound.py51
2 files changed, 51 insertions, 8 deletions
diff --git a/ml_exp/__main__.py b/ml_exp/__main__.py
index 83abb918e..3cb515d85 100644
--- a/ml_exp/__main__.py
+++ b/ml_exp/__main__.py
@@ -20,13 +20,5 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
"""
-# from ml_exp.do_ml import do_ml
-# from ml_exp.misc import plot_benchmarks
-# from ml_exp.read_qm7_data import read_qm7_data
-# from ml_exp.adj_matrix import fneig_matrix, adj_matrix
-# from ml_exp.c_matrix import c_matrix
-# from ml_exp.bob import bob
-# from ml_exp.bostuff import bok_cx
-
if __name__ == '__main__':
print('Ok!')
diff --git a/ml_exp/compound.py b/ml_exp/compound.py
new file mode 100644
index 000000000..6fd46fc3a
--- /dev/null
+++ b/ml_exp/compound.py
@@ -0,0 +1,51 @@
+"""MIT License
+
+Copyright (c) 2019 David Luevano Alvarado
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+"""
+import numpy as np
+
+
+class Compound:
+ def __init__(self, xyz=None):
+ self.n = None
+ self.atoms = None
+ self.coordinates = None
+
+ if xyz is not None:
+ self.read_xyz(xyz)
+
+ def read_xyz(self, filename):
+ """
+ Reads an xyz file and adds the corresponding data to the Compound.
+ filename: (path to) the xyz file.
+ """
+ with open(filename, 'r') as f:
+ lines = f.readlines()
+
+ self.n = int(lines[0])
+ self.atoms = []
+ self.coordinates = np.empty((self.n, 3), dtype=float)
+
+ for i, atom in enumerate(lines[2:self.n + 2]):
+ atom_d = atom.split()
+
+ self.atoms.append(atom_d[0])
+ self.coordinates[i] = np.asarray(atom_d[1:4], dtype=float)