@@ -51,7 +51,7 @@ def define(cls, spec):
5151 (ElectronicType .METAL , ElectronicType .INSULATOR , ElectronicType .UNKNOWN )
5252 )
5353 spec .inputs ['engines' ]['relax' ]['code' ].valid_type = CodeType ('abinit' )
54- spec .inputs ['protocol' ].valid_type = ChoiceType (('fast' , 'moderate' , 'precise' , 'verification-PBE-v1' ))
54+ spec .inputs ['protocol' ].valid_type = ChoiceType (('fast' , 'moderate' , 'precise' , 'verification-PBE-v1' , 'custom' ))
5555
5656 def _construct_builder (self , ** kwargs ) -> engine .ProcessBuilder : # noqa: PLR0912,PLR0915
5757 """Construct a process builder based on the provided keyword arguments.
@@ -62,6 +62,7 @@ def _construct_builder(self, **kwargs) -> engine.ProcessBuilder: # noqa: PLR091
6262 structure = kwargs ['structure' ]
6363 engines = kwargs ['engines' ]
6464 protocol = kwargs ['protocol' ]
65+ custom_protocol = kwargs .get ('custom_protocol' , None )
6566 spin_type = kwargs ['spin_type' ]
6667 relax_type = kwargs ['relax_type' ]
6768 electronic_type = kwargs ['electronic_type' ]
@@ -70,7 +71,12 @@ def _construct_builder(self, **kwargs) -> engine.ProcessBuilder: # noqa: PLR091
7071 threshold_stress = kwargs .get ('threshold_stress' , None )
7172 reference_workchain = kwargs .get ('reference_workchain' , None )
7273
73- protocol = copy .deepcopy (self .get_protocol (protocol ))
74+ if protocol == 'custom' :
75+ if custom_protocol is None :
76+ raise ValueError ('the `custom_protocol` input must be provided when the `protocol` input is set to `custom`.' )
77+ protocol = copy .deepcopy (custom_protocol )
78+ else :
79+ protocol = copy .deepcopy (self .get_protocol (protocol ))
7480 code = engines ['relax' ]['code' ]
7581
7682 pseudo_family_label = protocol .pop ('pseudo_family' )
@@ -187,31 +193,9 @@ def _construct_builder(self, **kwargs) -> engine.ProcessBuilder: # noqa: PLR091
187193 warnings .warn (f'input magnetization per site was None, setting it to { magnetization_per_site } ' )
188194 magnetization_per_site = np .array (magnetization_per_site )
189195
190- sum_is_zero = np .isclose (sum (magnetization_per_site ), 0.0 )
191- all_are_zero = np .all (np .isclose (magnetization_per_site , 0.0 ))
192- non_zero_mags = magnetization_per_site [~ np .isclose (magnetization_per_site , 0.0 )]
193- all_non_zero_pos = np .all (non_zero_mags > 0.0 )
194- all_non_zero_neg = np .all (non_zero_mags < 0.0 )
195-
196- if all_are_zero : # non-magnetic
197- warnings .warn (
198- 'all of the initial magnetizations per site are close to zero; doing a non-spin-polarized '
199- 'calculation'
200- )
201- elif (sum_is_zero and not all_are_zero ) or (
202- not all_non_zero_pos and not all_non_zero_neg
203- ): # antiferromagnetic
204- print ('Detected antiferromagnetic!' )
205- builder .abinit ['parameters' ]['nsppol' ] = 1 # antiferromagnetic system
206- builder .abinit ['parameters' ]['nspden' ] = 2 # scalar spin-magnetization in the z-axis
207- builder .abinit ['parameters' ]['spinat' ] = [[0.0 , 0.0 , mag ] for mag in magnetization_per_site ]
208- elif not all_are_zero and (all_non_zero_pos or all_non_zero_neg ): # ferromagnetic
209- print ('Detected ferromagnetic!' )
210- builder .abinit ['parameters' ]['nsppol' ] = 2 # collinear spin-polarization
211- builder .abinit ['parameters' ]['nspden' ] = 2 # scalar spin-magnetization in the z-axis
212- builder .abinit ['parameters' ]['spinat' ] = [[0.0 , 0.0 , mag ] for mag in magnetization_per_site ]
213- else :
214- raise ValueError (f'Initial magnetization { magnetization_per_site } is ambiguous' )
196+ builder .abinit ['parameters' ]['nsppol' ] = 2 # collinear spin-polarization
197+ builder .abinit ['parameters' ]['nspden' ] = 2 # scalar spin-magnetization in the z-axis
198+ builder .abinit ['parameters' ]['spinat' ] = [[0.0 , 0.0 , mag ] for mag in magnetization_per_site ]
215199 elif spin_type == SpinType .NON_COLLINEAR :
216200 if magnetization_per_site is None :
217201 magnetization_per_site = get_initial_magnetization (structure )
0 commit comments