Skip to content

Commit 7f11c45

Browse files
committed
Molecule.center now returns the translation vector. Fixed issue where Molecule.append was keeping a reference to the second molecule's arrays instead of copying them when its own arrays were empty
1 parent cf58f81 commit 7f11c45

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

moleculekit/molecule.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ def insertappend(index, data1, data2, append):
513513
if not isinstance(data2, np.ndarray):
514514
data2 = np.array([data2])
515515
if data1.size == 0:
516-
return data2
516+
return data2.copy() # To not insert a reference of second mol
517517
if data2.size == 0:
518518
return data1
519519
if append: # TODO: Remove this if numpy insert is as fast as append
@@ -558,7 +558,7 @@ def insertappend(index, data1, data2, append):
558558
self.bondtype = np.append(self.bondtype, mol.bondtype, axis=0)
559559
else:
560560
self.bonds = newbonds
561-
self.bondtype = mol.bondtype
561+
self.bondtype = mol.bondtype.copy()
562562

563563
for k in self._atom_and_coord_fields:
564564
if k == "serial":
@@ -1290,6 +1290,11 @@ def center(self, loc=(0, 0, 0), sel="all"):
12901290
Atom selection string of the atoms whose geometric center we want to center on the `loc` position.
12911291
See more `here <http://www.ks.uiuc.edu/Research/vmd/vmd-1.9.2/ug/node89.html>`__
12921292
1293+
Returns
1294+
-------
1295+
translation : np.ndarray
1296+
3D coordinates of the translation applied to the Molecule
1297+
12931298
Examples
12941299
--------
12951300
>>> mol=tryp.copy()
@@ -1301,9 +1306,9 @@ def center(self, loc=(0, 0, 0), sel="all"):
13011306
raise RuntimeError(
13021307
f'Atom selection "{sel}" selected 0 atoms. Cannot center Molecule.'
13031308
)
1304-
com = np.mean(self.coords[selbool, :, self.frame], 0)
1305-
self.moveBy(-com)
1306-
self.moveBy(loc)
1309+
translation = np.mean(self.coords[selbool, :, self.frame], 0)
1310+
self.moveBy(-translation + loc)
1311+
return -translation + loc
13071312

13081313
def read(
13091314
self,

0 commit comments

Comments
 (0)