@@ -306,7 +306,7 @@ def __init__(
306306 nsamples = 50 , # number of different points to sample in a run
307307 pbc = True ,
308308 ):
309-
309+
310310 super (HydrogenBondAutoCorrel , self ).__init__ (universe .trajectory )
311311 self .u = universe
312312
@@ -321,20 +321,16 @@ def __init__(
321321
322322 if exclusions is not None :
323323 if len (exclusions [0 ]) != len (exclusions [1 ]):
324- raise ValueError (
325- "'exclusion' must be two arrays of identical length"
326- )
327- self .exclusions = np .column_stack (
328- (exclusions [0 ], exclusions [1 ])
329- ).astype (np .intp )
324+ raise ValueError ("'exclusion' must be two arrays of identical length" )
325+ self .exclusions = np .column_stack ((exclusions [0 ], exclusions [1 ])).astype (
326+ np .intp
327+ )
330328 else :
331329 self .exclusions = None
332330
333331 self .bond_type = bond_type
334332 if self .bond_type not in ["continuous" , "intermittent" ]:
335- raise ValueError (
336- "bond_type must be either 'continuous' or 'intermittent'"
337- )
333+ raise ValueError ("bond_type must be either 'continuous' or 'intermittent'" )
338334
339335 self .a_crit = np .deg2rad (angle_crit )
340336 self .d_crit = dist_crit
@@ -354,6 +350,12 @@ def __init__(
354350 }
355351
356352 def _slice_traj (self , sample_time ):
353+
354+ try :
355+ self .u .trajectory [0 ]
356+ except TypeError :
357+ raise ValueError ("Trajectory is unable to be sliced" )
358+
357359 """Set up start and end points in the trajectory for the
358360 different passes
359361 """
@@ -364,9 +366,7 @@ def _slice_traj(self, sample_time):
364366 if req_frames > n_frames :
365367 warnings .warn (
366368 "Number of required frames ({}) greater than the"
367- " number of frames in trajectory ({})" .format (
368- req_frames , n_frames
369- ),
369+ " number of frames in trajectory ({})" .format (req_frames , n_frames ),
370370 RuntimeWarning ,
371371 )
372372
@@ -394,56 +394,56 @@ def _slice_traj(self, sample_time):
394394 self ._skip = 1
395395
396396 def run (self , start = None , stop = None , step = None , verbose = None , ** kwargs ):
397- """Run all the required passes
398-
399- Parameters
400- ----------
401- start : int, optional
402- start frame of trajectory (ignored, uses nruns logic)
403- stop : int, optional
404- end frame of trajectory (ignored, uses nruns logic)
405- step : int, optional
406- step size (ignored, uses nruns logic)
407- verbose : bool, optional
408- Show the progress bar
409- """
410- self ._slice_traj (self .sample_time )
397+ """Run all the required passes
411398
412- main_results = np .zeros_like (
413- np .arange (self ._starts [0 ], self ._stops [0 ], self ._skip ),
414- dtype = np .float32 ,
415- )
416- # for normalising later
417- counter = np .zeros_like (main_results , dtype = np .float32 )
418-
419- for i , (start , stop ) in ProgressBar (
420- enumerate (zip (self ._starts , self ._stops )),
421- total = self .nruns ,
422- desc = "Performing run" ,
423- verbose = verbose ,
424- ):
425-
426- # needed else trj seek thinks a np.int64 isn't an int?
427- results = self ._single_run (int (start ), int (stop ))
428-
429- nresults = len (results )
430- if nresults == len (main_results ):
431- main_results += results
432- counter += 1.0
433- else :
434- main_results [:nresults ] += results
435- counter [:nresults ] += 1.0
399+ Parameters
400+ ----------
401+ start : int, optional
402+ start frame of trajectory (ignored, uses nruns logic)
403+ stop : int, optional
404+ end frame of trajectory (ignored, uses nruns logic)
405+ step : int, optional
406+ step size (ignored, uses nruns logic)
407+ verbose : bool, optional
408+ Show the progress bar
409+ """
410+ self ._slice_traj (self .sample_time )
436411
437- main_results /= counter
412+ main_results = np .zeros_like (
413+ np .arange (self ._starts [0 ], self ._stops [0 ], self ._skip ),
414+ dtype = np .float32 ,
415+ )
416+ # for normalising later
417+ counter = np .zeros_like (main_results , dtype = np .float32 )
418+
419+ for i , (start , stop ) in ProgressBar (
420+ enumerate (zip (self ._starts , self ._stops )),
421+ total = self .nruns ,
422+ desc = "Performing run" ,
423+ verbose = verbose ,
424+ ):
425+
426+ # needed else trj seek thinks a np.int64 isn't an int?
427+ results = self ._single_run (int (start ), int (stop ))
428+
429+ nresults = len (results )
430+ if nresults == len (main_results ):
431+ main_results += results
432+ counter += 1.0
433+ else :
434+ main_results [:nresults ] += results
435+ counter [:nresults ] += 1.0
438436
439- self .solution ["time" ] = (
440- np .arange (len (main_results ), dtype = np .float32 )
441- * self .u .trajectory .dt
442- * self ._skip
443- )
444- self .solution ["results" ] = main_results
445-
446- return self
437+ main_results /= counter
438+
439+ self .solution ["time" ] = (
440+ np .arange (len (main_results ), dtype = np .float32 )
441+ * self .u .trajectory .dt
442+ * self ._skip
443+ )
444+ self .solution ["results" ] = main_results
445+
446+ return self
447447
448448 def _single_run (self , start , stop ):
449449 """Perform a single pass of the trajectory"""
@@ -477,9 +477,7 @@ def _single_run(self, start, stop):
477477 aidx = aidx [idx2 ]
478478
479479 nbonds = len (hidx ) # number of hbonds at t=0
480- results = np .zeros_like (
481- np .arange (start , stop , self ._skip ), dtype = np .float32
482- )
480+ results = np .zeros_like (np .arange (start , stop , self ._skip ), dtype = np .float32 )
483481
484482 if self .time_cut :
485483 # counter for time criteria
@@ -488,9 +486,7 @@ def _single_run(self, start, stop):
488486 for i , ts in enumerate (self .u .trajectory [start : stop : self ._skip ]):
489487 box = self .u .dimensions if self .pbc else None
490488
491- d = calc_bonds (
492- self .h .positions [hidx ], self .a .positions [aidx ], box = box
493- )
489+ d = calc_bonds (self .h .positions [hidx ], self .a .positions [aidx ], box = box )
494490 a = calc_angles (
495491 self .d .positions [hidx ],
496492 self .h .positions [hidx ],
@@ -615,9 +611,7 @@ def triple(x, A1, A2, tau1, tau2, tau3):
615611 """Sum of three exponential functions"""
616612 A3 = 1 - (A1 + A2 )
617613 return (
618- A1 * np .exp (- x / tau1 )
619- + A2 * np .exp (- x / tau2 )
620- + A3 * np .exp (- x / tau3 )
614+ A1 * np .exp (- x / tau1 ) + A2 * np .exp (- x / tau2 ) + A3 * np .exp (- x / tau3 )
621615 )
622616
623617 if self .bond_type == "continuous" :
@@ -658,9 +652,7 @@ def triple(x, A1, A2, tau1, tau2, tau3):
658652 self .solution ["ier" ] = ier
659653
660654 if ier in [1 , 2 , 3 , 4 ]: # solution found if ier is one of these values
661- self .solution ["estimate" ] = self ._my_solve (
662- self .solution ["time" ], * p
663- )
655+ self .solution ["estimate" ] = self ._my_solve (self .solution ["time" ], * p )
664656 else :
665657 warnings .warn ("Solution to results not found" , RuntimeWarning )
666658
0 commit comments