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