Changeset 304c775 in sasmodels for sasmodels/direct_model.py
- Timestamp:
- Oct 25, 2018 5:35:06 PM (5 years ago)
- Branches:
- master, core_shell_microgels, magnetic_model, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
- Children:
- 39a06c9
- Parents:
- 6d5601c
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/direct_model.py
r7b9e4dd r304c775 64 64 return calculator(call_details, values, cutoff, is_magnetic) 65 65 66 def call_ER(model_info, pars): 67 # type: (ModelInfo, ParameterSet) -> float 68 """ 69 Call the model ER function using *values*. 70 71 *model_info* is either *model.info* if you have a loaded model, 72 or *kernel.info* if you have a model kernel prepared for evaluation. 73 """ 74 if model_info.ER is None: 75 return 1.0 76 elif not model_info.parameters.form_volume_parameters: 77 # handle the case where ER is provided but model is not polydisperse 78 return model_info.ER() 79 else: 80 value, weight = _vol_pars(model_info, pars) 81 individual_radii = model_info.ER(*value) 82 return np.sum(weight*individual_radii) / np.sum(weight) 83 84 85 def call_VR(model_info, pars): 86 # type: (ModelInfo, ParameterSet) -> float 87 """ 88 Call the model VR function using *pars*. 89 90 *model_info* is either *model.info* if you have a loaded model, 91 or *kernel.info* if you have a model kernel prepared for evaluation. 92 """ 93 if model_info.VR is None: 94 return 1.0 95 elif not model_info.parameters.form_volume_parameters: 96 # handle the case where ER is provided but model is not polydisperse 97 return model_info.VR() 98 else: 99 value, weight = _vol_pars(model_info, pars) 100 whole, part = model_info.VR(*value) 101 return np.sum(weight*part)/np.sum(weight*whole) 102 66 def call_Fq(calculator, pars, cutoff=0., mono=False): 67 # type: (Kernel, ParameterSet, float, bool) -> np.ndarray 68 """ 69 Like :func:`call_kernel`, but returning F, F^2, R_eff, V, V_form/V_shell. 70 """ 71 R_eff_type = int(pars.pop('radius_effective_type', 1.0)) 72 mesh = get_mesh(calculator.info, pars, dim=calculator.dim, mono=mono) 73 #print("pars", list(zip(*mesh))[0]) 74 call_details, values, is_magnetic = make_kernel_args(calculator, mesh) 75 #print("values:", values) 76 return calculator.Fq(call_details, values, cutoff, is_magnetic, R_eff_type) 103 77 104 78 def call_profile(model_info, **pars): … … 419 393 model_name = sys.argv[1] 420 394 call = sys.argv[2].upper() 421 if call != "ER_VR": 422 try: 423 values = [float(v) for v in call.split(',')] 424 except ValueError: 425 values = [] 426 if len(values) == 1: 427 q, = values 428 data = empty_data1D([q]) 429 elif len(values) == 2: 430 qx, qy = values 431 data = empty_data2D([qx], [qy]) 432 else: 433 print("use q or qx,qy or ER or VR") 434 sys.exit(1) 395 try: 396 values = [float(v) for v in call.split(',')] 397 except ValueError: 398 values = [] 399 if len(values) == 1: 400 q, = values 401 data = empty_data1D([q]) 402 elif len(values) == 2: 403 qx, qy = values 404 data = empty_data2D([qx], [qy]) 435 405 else: 436 data = empty_data1D([0.001]) # Data not used in ER/VR 406 print("use q or qx,qy") 407 sys.exit(1) 437 408 438 409 model_info = load_model_info(model_name) … … 442 413 for pair in sys.argv[3:] 443 414 for k, v in [pair.split('=')]) 444 if call == "ER_VR": 445 ER = call_ER(model_info, pars) 446 VR = call_VR(model_info, pars) 447 print(ER, VR) 448 else: 449 Iq = calculator(**pars) 450 print(Iq[0]) 415 Iq = calculator(**pars) 416 print(Iq[0]) 451 417 452 418 if __name__ == "__main__":
Note: See TracChangeset
for help on using the changeset viewer.