Permalink
Browse files

added copy methods

  • Loading branch information...
1 parent f150df3 commit 79d9a3c9fb363e573ec2825010d9554bde419564 @gabrielelanaro gabrielelanaro committed Feb 15, 2012
Showing with 24 additions and 1 deletion.
  1. +24 −1 chemlab/core/molecule.py
View
@@ -61,6 +61,28 @@ def guess_bonds(self, threshold=0.1):
self.bonds.append(Bond(atom1, atom))
+ def copy(self):
+ mol = Molecule([atom.copy() for atom in self.atoms],
+ [])
+
+ mol.bonds = []
+ for bond in self.bonds:
+ a1_id = bond.start.id
+ a2_id = bond.end.id
+
+ mol.bonds.append(Bond(mol.by_id(a1_id), mol.by_id(a2_id)))
+
+ return mol
+
+
+ def by_id(self, id):
+
+ for atom in self.atoms:
+ if atom.id == id:
+ return atom
+
+ raise Exception("No atom with such id: % d"%id)
+
def det_angles(self):
self.angles=[]
@@ -99,8 +121,9 @@ def __init__(self,id,type,coords):
self.coords = np.array(coords)
self.atno = symbols.symbol_list.index(type) + 1
-
+ def copy(self):
+ return Atom(self.id, self.type, np.copy(self.coords))
class Bond:

0 comments on commit 79d9a3c

Please sign in to comment.