-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmolio2.py
More file actions
41 lines (29 loc) · 997 Bytes
/
molio2.py
File metadata and controls
41 lines (29 loc) · 997 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import numpy as np
from atom import Atom,Bond
def read_atomline(atomline:str):
line = atomline.split()
coordinate = np.array([float(x) for x in line[:3]])
symbol = line[4]
return symbol,coordinate
def read_bondline(bondline:str):
line = bondline.split()
def read_molblcok(molblock:str):
lines = molblock.splitlines()
num_atoms = int(lines[3].split()[0])
num_bonds = int(lines[3].split()[1])
lines_atoms = lines[4 : 4 + num_atoms]
lines_bonds = lines[4 + num_atoms : 4 + num_atoms + num_bonds]
atoms = []
for idx,line in enumerate(lines_atoms):
l = line.split()
coordinate = np.array([float(x) for x in l[:3]])
symbol = line[4]
atoms.append(Atom(idx,symbol,coordinate))
bonds = []
for idx,line in enumerate(lines_bonds):
l = line.split()
a1 = int(l[0])
a2 = int(l[1])
a3 = int(l[2])
bonds.append(Bond(idx,[atoms[a1],atoms[a2]],a3))
return atoms, bonds