-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathatom.py
More file actions
37 lines (28 loc) · 1.3 KB
/
atom.py
File metadata and controls
37 lines (28 loc) · 1.3 KB
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
import numpy as np
class Atom:
"""Class representing a chmeical atom. Each atom has coordinates (x,y,z) and a name."""
def __init__(self, name, coords):
"""returns new atom.Atom object"""
self.name, self.coords = name, coords
def copy(self):
"""Method that returns a deep copy of the current atom"""
coords = np.copy(self.coords)
return Atom(self.name, coords)
def move(self, p):
"""Method that moves the atom by a specified 1x3 [X,Y,Z] list of floats"""
self.coords += p
def to_pdb_str(self, acount=1):
"""Creates a string representation of the atom that is compatible with the PDB format"""
if self == None:
raise TypeError
return "ATOM {:6d} P C A 1 {:11.3f}{:8.3f}{:8.3f} 1.00 62.18 P\n".format(
acount,
self.coords[0],
self.coords[1],
self.coords[2])
def __str__(self):
"""Returns the string representation of the object with the format NAME X Y Z"""
return self.name + " " + ' '.join([str(val) for val in self.coords])
def __repr__(self):
"""Returns the string representation of the object with the format NAME X Y Z. Used for debugging purposes only"""
return str(self)