@@ -380,85 +380,80 @@ def write_input_file(self) -> None:
380380 with open (os .path .join (self .local_path , input_filenames [self .job_adapter ]), 'w' ) as f :
381381 f .write (Template (input_template ).render (** input_dict ))
382382 def generate_qchem_scan_angles (self ,start_angle : int , step : int ) -> (int , int , int , int ):
383- """
384- Generates the angles for a Q-Chem scan. The scan is split into two parts, one from start_angle to 180, and one from -180 to end_angle.
385-
386- Parameters
387- ----------
388- start_angle : int
389- The starting angle for the scan
390- step : int
391- The step size for the scan
392-
393- Returns
394- -------
395- scan1_start : int
396- The starting angle for the first part of the scan
397- scan1_end : int
398- The ending angle for the first part of the scan
399- scan2_start : int
400- The starting angle for the second part of the scan
401- scan2_end : int
402- The ending angle for the second part of the scan
403- """
404-
405- # First, we need to check that the start_angle is within the range of -180 to 180, and if not, convert it to be within that range
406- if start_angle > 180 :
407- start_angle = start_angle - 360
408-
409-
410- # This sets the end angle but does not take into account the limit of -180 to 180
411- end_angle = start_angle - step
412-
413- # This function wraps the scan2_start within the range of -180 to 180
414- wrap_within_range = lambda number , addition : (number + addition ) % 360 - 360 if (number + addition ) % 360 > 180 else (number + addition ) % 360
415-
416- # This function converts the angles to be within the range of -180 to 180
417- convert_angle = lambda angle : angle % 360 if angle >= 0 else ( angle % 360 if angle <= - 180 else (angle % 360 ) - 360 )
418-
419- # This converts the angles to be within the range of -180 to 180
420- start_angle = convert_angle (start_angle )
421- end_angle = convert_angle (end_angle )
383+ """Generates angles for a Q-Chem dihedral scan, split into two segments.
384+
385+ This function computes the angles for a Q-Chem dihedral scan. The scan is
386+ divided into two parts: one spanning from the start_angle to 180 degrees,
387+ and the other from -180 degrees to the calculated end_angle based on the
388+ step size.
389+
390+ Args:
391+ start_angle (int): The initial angle for the scan.
392+ step (int): The incremental step size for the scan.
393+
394+ Returns:
395+ tuple of int: A tuple containing the start and end angles for both
396+ scan segments. It includes scan1_start, scan1_end,
397+ scan2_start, and scan2_end.
398+ """
399+
400+ # First, we need to check that the start_angle is within the range of -180 to 180, and if not, convert it to be within that range
401+ if start_angle > 180 :
402+ start_angle = start_angle - 360
403+
404+
405+ # This sets the end angle but does not take into account the limit of -180 to 180
406+ end_angle = start_angle - step
407+
408+ # This function wraps the scan2_start within the range of -180 to 180
409+ wrap_within_range = lambda number , addition : (number + addition ) % 360 - 360 if (number + addition ) % 360 > 180 else (number + addition ) % 360
410+
411+ # This function converts the angles to be within the range of -180 to 180
412+ convert_angle = lambda angle : angle % 360 if angle >= 0 else ( angle % 360 if angle <= - 180 else (angle % 360 ) - 360 )
413+
414+ # This converts the angles to be within the range of -180 to 180
415+ start_angle = convert_angle (start_angle )
416+ end_angle = convert_angle (end_angle )
417+
418+ if start_angle == 0 and end_angle == 0 :
419+ scan1_start = start_angle
420+ scan1_end = 180
421+ scan2_start = - 180
422+ scan2_end = end_angle
423+ elif start_angle == 180 :
424+ # This is a special case because the scan will be from 180 to 180
425+ # This is not allowed in Q-Chem so we split it into two scans
426+ # Arguably this could be done in one scan but it is easier to do it this way
427+ # We will need to find the starting angle that when added by the step size will be 180
428+ target_sum = 180
429+ quotient = target_sum // step
430+ starting_number = target_sum - (quotient * step )
431+ scan1_start = starting_number
432+ scan1_end = 180
433+ scan2_start = - 180
434+ scan2_end = scan1_start - step
435+ elif start_angle <= end_angle :
436+ scan1_start = start_angle
437+ scan1_end = start_angle + (step * ((180 - start_angle )// step ))
438+ scan2_start = convert_angle (scan1_end )
439+ scan2_end = end_angle
440+ elif (start_angle + step ) > 180 :
441+ # This is a special case because the scan will be from, for example, 178 to 178 for the first scan. Therefore, we should make it a single scan from end angle, 178, step size
442+ scan1_end = start_angle
443+ scan1_start = wrap_within_range (scan1_end , step )
444+ scan2_start = 0
445+ scan2_end = 0
446+ else :
447+ scan1_start = start_angle
448+ scan1_end = start_angle + (step * ((180 - start_angle )// step ))
449+ scan2_start = wrap_within_range (scan1_end , step )
450+ scan2_end = end_angle
422451
423- if start_angle == 0 and end_angle == 0 :
424- scan1_start = start_angle
425- scan1_end = 180
426- scan2_start = - 180
427- scan2_end = end_angle
428- elif start_angle == 180 :
429- # This is a special case because the scan will be from 180 to 180
430- # This is not allowed in Q-Chem so we split it into two scans
431- # Arguably this could be done in one scan but it is easier to do it this way
432- # We will need to find the starting angle that when added by the step size will be 180
433- target_sum = 180
434- quotient = target_sum // step
435- starting_number = target_sum - (quotient * step )
436- scan1_start = starting_number
437- scan1_end = 180
438- scan2_start = - 180
439- scan2_end = scan1_start - step
440- elif start_angle <= end_angle :
441- scan1_start = start_angle
442- scan1_end = start_angle + (step * ((180 - start_angle )// step ))
443- scan2_start = convert_angle (scan1_end )
444- scan2_end = end_angle
445- elif (start_angle + step ) > 180 :
446- # This is a special case because the scan will be from, for example, 178 to 178 for the first scan. Therefore, we should make it a single scan from end angle, 178, step size
447- scan1_end = start_angle
448- scan1_start = wrap_within_range (scan1_end , step )
449- scan2_start = 0
450- scan2_end = 0
451- else :
452- scan1_start = start_angle
453- scan1_end = start_angle + (step * ((180 - start_angle )// step ))
454- scan2_start = wrap_within_range (scan1_end , step )
455- scan2_end = end_angle
456-
457- if scan2_start == scan2_end :
458- scan2_start = 0
459- scan2_end = 0
460-
461- return int (scan1_start ), int (scan1_end ), int (scan2_start ), int (scan2_end )
452+ if scan2_start == scan2_end :
453+ scan2_start = 0
454+ scan2_end = 0
455+
456+ return int (scan1_start ), int (scan1_end ), int (scan2_start ), int (scan2_end )
462457
463458 def generate_scan_angles (self , req_angle : int , step : int ) -> (int , int ):
464459
0 commit comments