This addresses #66 by replacing the loop using NumPy matrix multiplication. These changes produce the same results but much faster. I timed the code before and after this change (iterating 100x to get a reasonable average) for 2 different molecules on 2 computers, giving the following results:
Machine
System
Original (s)
Vectorized (s)
Speed-up
AMD X4 965
mAb
0.173502459526
0.00427374839783
40x
MacBook Pro
mAb
0.108209969997
0.00162575006485
67x
AMD X4 965
4x167 NCP
0.853358361721
0.0248510980606
34x
MacBook Pro
4x167 NCP
0.555229699612
0.00928428173065
60x
This is the code I used for testing
import os
import time
import sasmol.system as system
# pdb_fname = '4x167_ncp.pdb'
pdb_fname = 'aligned_mab.pdb'
n = 100
assert os.path.exists(pdb_fname), 'no such file: {}'.format(pdb_fname)
mol = system.Molecule(pdb_fname)
tic = time.time()
for i in range(n):
mol.calculate_principal_moments_of_inertia(0)
toc = time.time() - tic
print('{} principal momement calculations of {} took {} seconds'.format(
n, pdb_fname, toc))
print('{} s per iteration'.format(toc / n))
This addresses #66 by replacing the loop using NumPy matrix multiplication. These changes produce the same results but much faster. I timed the code before and after this change (iterating 100x to get a reasonable average) for 2 different molecules on 2 computers, giving the following results:
This is the code I used for testing