@@ -564,20 +564,78 @@ def step(self, num_steps: int = 1):
564
564
565
565
self ._omm_mols .getIntegrator ().step (num_steps )
566
566
567
- def run_minimisation (self , max_iterations : int ):
567
+ def get_minimisation_log (self ):
568
+ """
569
+ Return the log from the last minimisation
570
+ """
571
+ if self .is_null ():
572
+ return None
573
+ else :
574
+ try :
575
+ return self ._minimisation_log
576
+ except Exception :
577
+ return None
578
+
579
+ def run_minimisation (
580
+ self ,
581
+ max_iterations : int = 10000 ,
582
+ tolerance : float = 10.0 ,
583
+ max_restarts : int = 10 ,
584
+ max_ratchets : int = 20 ,
585
+ ratchet_frequency : int = 500 ,
586
+ starting_k : float = 100.0 ,
587
+ ratchet_scale : float = 2.0 ,
588
+ max_constraint_error : float = 0.001 ,
589
+ ):
568
590
"""
569
591
Internal method that runs minimisation on the molecules.
570
592
593
+ If the system is constrained, then a ratcheting algorithm is used.
594
+ The constraints are replaced by harmonic restraints with an
595
+ force constant based on `tolerance` and `starting_k`. Minimisation
596
+ is performed, with the actual constrained bond lengths checked
597
+ whenever minimisation converges, or when ratchet_frequency steps
598
+ have completed (whichever is sooner). The force constant of
599
+ the restraints is ratcheted up by `ratchet_scale`, and minimisation
600
+ continues until there is no large change in energy or the maximum
601
+ number of ratchets has been reached. In addition, at each ratchet,
602
+ the actual bond lengths of constrained bonds are compared against
603
+ the constrained values. If these have drifted too far away from
604
+ the constrained values, then the minimisation is restarted,
605
+ going back to the starting conformation and starting minimisation
606
+ at one higher ratchet level. This will repeat a maximum of
607
+ `max_restarts` times.
608
+
609
+ If a stable structure cannot be reached, then an exception
610
+ will be raised.
611
+
571
612
Parameters:
572
613
573
614
- max_iterations (int): The maximum number of iterations to run
615
+ - tolerance (float): The tolerance to use for the minimisation
616
+ - max_restarts (int): The maximum number of restarts before giving up
617
+ - max_ratchets (int): The maximum number of ratchets before giving up
618
+ - ratchet_frequency (int): The maximum number of steps between ratchets
619
+ - starting_k (float): The starting value of k for the minimisation
620
+ - ratchet_scale (float): The amount to scale k at each ratchet
621
+ - max_constraint_error (float): The maximum error in the constraint in nm
574
622
"""
575
623
from ..legacy .Convert import minimise_openmm_context
576
624
577
625
if max_iterations <= 0 :
578
626
max_iterations = 0
579
627
580
- minimise_openmm_context (self ._omm_mols , max_iterations = max_iterations )
628
+ self ._minimisation_log = minimise_openmm_context (
629
+ self ._omm_mols ,
630
+ tolerance = tolerance ,
631
+ max_iterations = max_iterations ,
632
+ max_restarts = max_restarts ,
633
+ max_ratchets = max_ratchets ,
634
+ ratchet_frequency = ratchet_frequency ,
635
+ starting_k = starting_k ,
636
+ ratchet_scale = ratchet_scale ,
637
+ max_constraint_error = max_constraint_error ,
638
+ )
581
639
582
640
def _rebuild_and_minimise (self ):
583
641
if self .is_null ():
@@ -600,7 +658,7 @@ def _rebuild_and_minimise(self):
600
658
601
659
self ._omm_mols = to (self ._sire_mols , "openmm" , map = self ._map )
602
660
603
- self .run_minimisation (max_iterations = 10000 )
661
+ self .run_minimisation ()
604
662
605
663
def run (
606
664
self ,
@@ -1032,18 +1090,57 @@ def __repr__(self):
1032
1090
def minimise (
1033
1091
self ,
1034
1092
max_iterations : int = 10000 ,
1093
+ tolerance : float = 10.0 ,
1094
+ max_restarts : int = 10 ,
1095
+ max_ratchets : int = 20 ,
1096
+ ratchet_frequency : int = 500 ,
1097
+ starting_k : float = 100.0 ,
1098
+ ratchet_scale : float = 2.0 ,
1099
+ max_constraint_error : float = 0.001 ,
1035
1100
):
1036
1101
"""
1037
- Perform minimisation on the molecules, running a maximum
1038
- of max_iterations iterations.
1102
+ Internal method that runs minimisation on the molecules.
1103
+
1104
+ If the system is constrained, then a ratcheting algorithm is used.
1105
+ The constraints are replaced by harmonic restraints with an
1106
+ force constant based on `tolerance` and `starting_k`. Minimisation
1107
+ is performed, with the actual constrained bond lengths checked
1108
+ whenever minimisation converges, or when ratchet_frequency steps
1109
+ have completed (whichever is sooner). The force constant of
1110
+ the restraints is ratcheted up by `ratchet_scale`, and minimisation
1111
+ continues until there is no large change in energy or the maximum
1112
+ number of ratchets has been reached. In addition, at each ratchet,
1113
+ the actual bond lengths of constrained bonds are compared against
1114
+ the constrained values. If these have drifted too far away from
1115
+ the constrained values, then the minimisation is restarted,
1116
+ going back to the starting conformation and starting minimisation
1117
+ at one higher ratchet level. This will repeat a maximum of
1118
+ `max_restarts` times.
1119
+
1120
+ If a stable structure cannot be reached, then an exception
1121
+ will be raised.
1039
1122
1040
1123
Parameters:
1041
1124
1042
1125
- max_iterations (int): The maximum number of iterations to run
1126
+ - tolerance (float): The tolerance to use for the minimisation
1127
+ - max_restarts (int): The maximum number of restarts before giving up
1128
+ - max_ratchets (int): The maximum number of ratchets before giving up
1129
+ - ratchet_frequency (int): The maximum number of steps between ratchets
1130
+ - starting_k (float): The starting value of k for the minimisation
1131
+ - ratchet_scale (float): The amount to scale k at each ratchet
1132
+ - max_constraint_error (float): The maximum error in the constraints in nm
1043
1133
"""
1044
1134
if not self ._d .is_null ():
1045
1135
self ._d .run_minimisation (
1046
1136
max_iterations = max_iterations ,
1137
+ tolerance = tolerance ,
1138
+ max_restarts = max_restarts ,
1139
+ max_ratchets = max_ratchets ,
1140
+ ratchet_frequency = ratchet_frequency ,
1141
+ starting_k = starting_k ,
1142
+ ratchet_scale = ratchet_scale ,
1143
+ max_constraint_error = max_constraint_error ,
1047
1144
)
1048
1145
1049
1146
return self
0 commit comments