summaryrefslogtreecommitdiff
path: root/ml_exp/compound.py
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 /ml_exp/compound.py
parent0c91ee8b6c968457cff1d968cf69add73902bd11 (diff)
Add basic compound object
Diffstat (limited to 'ml_exp/compound.py')
-rw-r--r--ml_exp/compound.py51
1 files changed, 51 insertions, 0 deletions
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)