Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accessing and modifying model parameters via REPL - SAFTgammaMie #145

Closed
michelevalsecchi opened this issue Mar 1, 2023 · 10 comments
Closed

Comments

@michelevalsecchi
Copy link

michelevalsecchi commented Mar 1, 2023

Hi, I have been accessing and modifying the parameters of a water/PEG model (model = SAFTgammaMie(["water","PEG_1sit"])) in Clapeyron directly via the Julia REPL by using the "model.vrmodel.params" and "model.params" attributes. However, I have noticed that when there are many association sites the "model.vrmodel.params.epsilon_assoc.values" and "model.params.epsilon_assoc.values" vectors (same for bondvol) contain a different number of entries. In particular, it seems that the vrmodel one is missing some association values. Does this impact the calculations at all?

On another note, I have been trying to modify the parameters and was wondering if changing both the entries in "model.vrmodel.params" and "model.params" (accounting for symmetry) is sufficient to temporarily update a given parameter.

Thanks in advance for the help!

@longemen3000
Copy link
Member

longemen3000 commented Mar 1, 2023

Hi, if you are updating directly the values on the REPL, the ones actually used in the calculation are the ones in model.vrmodel.params.epsilon_assoc. The long answer is that, because the association solver only takes component-based site pairs, we do a transformation from group-based sites to component-based sites, and those are stored in vrmodel.

On another note, I have been trying to modify the parameters and was wondering if changing both the entries in "model.vrmodel.params" and "model.params" (accounting for symmetry) is sufficient to temporarily update a given parameter.

If you don't modify the number of groups or sites, and in this particular case that is correct. we have something of a general function, recombine! that recalculates every needed value (including association parameters, parameter caches, etc) from some starting parameters (In this particular case, the original parameters are the group-based ones and the calculated ones are in model.vrmodel. UNIFAC also has a cache that is recalculated when recombine! is called.)

By the way, you can modify directly the pair parameters and symmetry is respected:

julia> param = PairParam("sym",["1","2"],rand(2,2))
2×2 PairParam{Float64}(["1", "2"]) with values:
 0.576906  0.517533
 0.818169  0.981202

#setting a non-diagonal value (i,j) will also set (j,i),
#you can op out of this by calling setindex!(param,val,i,j,false)
julia> param[1,2] = 100 
100

julia> param
2×2 PairParam{Float64}(["1", "2"]) with values:
   0.576906  100.0
 100.0         0.981202

However, I have noticed that when there are many association sites the "model.vrmodel.params.epsilon_assoc.values" and "model.params.epsilon_assoc.values" vectors (same for bondvol) contain a different number of entries. In particular, it seems that the vrmodel one is missing some association values. Does this impact the calculations at all?

It shouldn't, but just to be sure, can you send what are your model values? (model.params.epsilon_assoc, model.params.bondvol, model.vrmodels.params.epsilon_assoc and model.vrmodels.params.bondvol) ?

@michelevalsecchi
Copy link
Author

Thanks for the quick answer! I have been trying recombine! and it works as expected, thanks! Regarding the different number of entries, I am assuming the reason might be that PEG is heteronuclear and has two associating groups. See the attached screenshots for reference.

bondvol
epsilon_assoc

@michelevalsecchi
Copy link
Author

Notably also the dispersion is modified. The numbers don't even always match in the two sets in this case. Is this due to the transformation you mentioned?

epsilon

@longemen3000
Copy link
Member

longemen3000 commented Mar 2, 2023

The dispersion data is fine, because the values in that VR model are GC-averaged (we move from 4 groups to 2 components) . In the other part, there is definitely something going on with the association. Can you send me the outputs of model.sites and model.vrmodel.sites? If those are normal, there is definitely a bug

@michelevalsecchi
Copy link
Author

Here they are. As you suspected, it seems that the model.sites is not counting the PEG sites properly. It's pretty interesting however that the error here is on model, not model.vrmodel

sites

@longemen3000
Copy link
Member

longemen3000 commented Mar 2, 2023

ok, i can reproduce your bug. reproducer:

like_data = """
Clapeyron Database File
SAFTgammaMie Like Parameters [csvtype = like,grouptype = SAFTgammaMie]
species,vst,S,lambda_r,lambda_a,sigma,epsilon,n_H,n_e1,n_e2,Mw
CH2_PEO,1,1,12,6,4,300,0,0,0,100
cO_1sit,1,1,12,6,4,300,0,1,0,100
"""

mw_data = """
Clapeyron Database File
SAFTgammaMie Like Parameters
species,Mw
CH2_PEO,100
cO_1sit,100
"""

assoc_data = """
Clapeyron Database File,,,,,,
SAFTgammaMie Assoc Parameters [csvtype = assoc,grouptype = SAFTgammaMie]
species1,site1,species2,site2,epsilon_assoc,bondvol,source
H2O,H,cO_1sit,e1,2193.2,5e-29,
CH2OH,H,cO_1sit,e1,1572.5,4.331e-28,
"""

group_data = """
Clapeyron Database File,
SAFTgammaMie Groups [csvtype = groups,grouptype = SAFTgammaMie]
species,groups
PEG_1sit,"[""CH2_PEO"" => 2000,""cO_1sit"" => 1000,""CH2OH"" => 2]"
"""

model = SAFTgammaMie(["water","PEG_1sit"],userlocations = [like_data,assoc_data,mw_data],group_userlocations = [group_data])

@michelevalsecchi
Copy link
Author

michelevalsecchi commented Mar 3, 2023

Great, thanks for the time! Do you think this affects calculations / is hard to fix?

PS: I was using recombine! and I noticed that interaction parameters calculated by default using combining rules (i.e. no entry in the databanks) are reset even if their value is set via model.params. This does not happen for the ones that have an entry. Is this behaviour intended?

@longemen3000
Copy link
Member

I plan to get a new release today with the fix.

interaction parameters calculated by default using combining rules (i.e. no entry in the databanks) are reset even if their value is set via model.params. This does not happen for the ones that have an entry. Is this behaviour intended?

Yes, we have a boolean flag for values that are not set in params.param.ismissingvalues. if that is false, then the value shouldn't be touched during recombine

@michelevalsecchi
Copy link
Author

OK fantastic! I'll try the new version ASAP and play with the boolean flag. Thanks a lot for the support!

longemen3000 added a commit that referenced this issue Mar 4, 2023
longemen3000 added a commit that referenced this issue Mar 4, 2023
@longemen3000
Copy link
Member

This was fixed (with tests),so I'm gonna close this issue for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants