SCM-NV / pyZacros

Python Library for Automating Zacros Simulations
Other
7 stars 2 forks source link

Neighbouring of ElementaryReactions #81

Closed lopeztarifa closed 1 year ago

lopeztarifa commented 1 year ago

Hi @nfaguirrec ,

I am trying to reproduce the following reaction:

reversible_step O2_adsorption

  gas_reacs_prods  O2 -1
  sites 2
  neighboring 1-2
  initial
    1 *    1
    2 *    1                                                                                     
  final
    1 O*   1
    2 O*   1

  variant brg_brg
    site_types   brg brg
    pre_expon    7.980e+07
    pe_ratio     9.431e-09
    activ_eng    0.00
  end_variant

end_reversible_step

For that, I create the corresponding pz.ElementaryReaction using a neighboring=[(1, 2)]. The mechanism_input.dat file that pyZacros writes:

reversible_step Reaction1
  gas_reacs_prods O2 -1
  sites 2
  neighboring 2-3            # I expect a 1-2 instead
  initial
    1 * 1 
    2 * 1 
  final
    1 O* 1
    2 O* 1
  site_types brg brg 
  pre_expon  7.98000e+07
  pe_ratio  9.43100e-09
  activ_eng  0.00000e+00
end_reversible_step

That makes Zacros to crash:

Mechanism setup:
~~~~~~~~~~~~~~~~

***************

Error code 4009 from mechanism_parser_module: error in elementary step neighboring list in mechanism_input.dat.

More information: 
Site number 3 referenced in neighboring input in line 6 is out of range 1:2 for this elementary step.

***************

I guess the reason is the output of the ElementaryReaction: https://github.com/SCM-NV/pyZacros/blob/65fc06077ad6cc7b75c60a004c86640a4f39cea6/core/ElementaryReaction.py#L232

Any reasons why a +1 is added to the neighboring numbers? I think is confusing :S

Thanks

nfaguirrec commented 1 year ago

Hi @lopeztarifa,

The keyword "variant" is not yet implemented in pyZacros. However, I agree with the line you wrote, "# I expect a 1-2 instead", so I'll check it. Regarding the +1, it is because I need to convert the python zero-based indexing to zacros one-based indexing.

Nestor

lopeztarifa commented 1 year ago

Thanks for taking a look!

nfaguirrec commented 1 year ago

I used the code shown below, and it works as expected:

import scm.pyzacros as pz

O2_g = pz.Species("O2")

s0 = pz.Species("*")
O_s = pz.Species("O*")

O2_ads = pz.ElementaryReaction(initial=[s0,s0,O2_g],
                               final=[O_s,O_s],
                               site_types=['brg','brg'],
                               neighboring=[(0,1)],
                               reversible=True,
                               pre_expon=7.980e+07,
                               pe_ratio=9.431e-09,
                               activation_energy=0.000,
                               label="O2_adsorption")

print(O2_ads)

This is the output:

reversible_step O2_adsorption
  gas_reacs_prods O2 -1
  sites 2
  neighboring 1-2
  initial
    1 * 1
    2 * 1
  final
    1 O* 1
    2 O* 1
  site_types brg brg
  pre_expon  7.98000e+07
  pe_ratio  9.43100e-09
  activ_eng  0.00000e+00
end_reversible_step

The problem is the indexing you are using. Remember that python uses zero-based indexing, so the neighboring must to be [(0,1)] and not [(1,2)].

Nestor

lopeztarifa commented 1 year ago

Yes, I know. But I think for users would be better to have the same neighboring indexing as Zacros, wouldn't be?

lopeztarifa commented 1 year ago

The concept of neighboring is based on the Python index. Users copying/pasting from Zacros inputs should change them accordingly.