ReactionMechanismGenerator / ARC

ARC - Automatic Rate Calculator
https://reactionmechanismgenerator.github.io/ARC/index.html
MIT License
43 stars 21 forks source link

IndexError: List Index Out of Range #631

Closed calvinp0 closed 1 year ago

calvinp0 commented 1 year ago

Describe the bug An arc reaction run returned the following error:

Traceback (most recent call last):
  File "/home/calvin.p/Code/ARC//ARC.py", line 69, in <module>
    main()
  File "/home/calvin.p/Code/ARC//ARC.py", line 65, in main
    arc_object.execute()
  File "/home/calvin.p/Code/ARC/arc/main.py", line 583, in execute
    fine_only=self.fine_only,
  File "/home/calvin.p/Code/ARC/arc/scheduler.py", line 486, in __init__
    self.schedule_jobs()
  File "/home/calvin.p/Code/ARC/arc/scheduler.py", line 575, in schedule_jobs
    self.spawn_post_opt_jobs(label=label, job_name=job_name)
  File "/home/calvin.p/Code/ARC/arc/scheduler.py", line 1459, in spawn_post_opt_jobs
    self.spawn_ts_jobs()
  File "/home/calvin.p/Code/ARC/arc/scheduler.py", line 1483, in spawn_ts_jobs
    tsg=tsg_index,
  File "/home/calvin.p/Code/ARC/arc/scheduler.py", line 832, in run_job
    job.execute()
  File "/home/calvin.p/Code/ARC/arc/job/adapter.py", line 317, in execute
    self.execute_incore()
  File "/home/calvin.p/Code/ARC/arc/job/adapters/ts/heuristics.py", line 280, in execute_incore
    dihedral_increment=self.dihedral_increment,
  File "/home/calvin.p/Code/ARC/arc/job/adapters/ts/heuristics.py", line 1002, in h_abstraction
    reactant_2=arc_reaction.r_species[int(not reactants_reversed)],
IndexError: list index out of range

Uncertain which reaction it was as the error does not provide enough information. However, I believe it was one of these reactions:

TS4: r_75_[S] + r_75_[S]S <=> r_75_[SH] + r_75_[S][S]
(identified as belonging to RMG family H_Abstraction)

TS5: r_76_[S]S + r_76_[S]S <=> r_76_SS + r_76_[S][S]
(identified as belonging to RMG family H_Abstraction)

The last information in the arc.log was regarding TS5 which I believe is this:

- arkane_file: null
  bond_corrections: {}
  charge: 0
  chosen_ts: null
  chosen_ts_list: []
  chosen_ts_method: null
  compute_thermo: false
  consider_all_diastereomers: true
  force_field: MMFF94s
  is_ts: true
  label: TS5
  long_thermo_description: ''
  multiplicity: 3
  number_of_rotors: 0
  rxn_index: 5
  rxn_label: r_76_[S]S + r_76_[S]S <=> r_76_SS + r_76_[S][S]
  rxn_zone_atom_indices: null
  successful_methods: []
  ts_checks:
    E0: null
    IRC: null
    e_elect: null
    freq: null
    normal_mode_displacement: null
    warnings: ''
  ts_conf_spawned: false
  ts_guesses: []
  ts_guesses_exhausted: false
  ts_number: 5
  ts_report: ''
  unsuccessful_methods: []

input.zip

calvinp0 commented 1 year ago
        zmats = list()
        for d2, d3 in d2_d3_product:
            xyz_guess = None
            try:
                xyz_guess = combine_coordinates_with_redundant_atoms(
                    xyz_1=arc_reactant.get_xyz(),
                    xyz_2=arc_product.get_xyz(),
                    mol_1=rmg_reactant_mol,
                    mol_2=rmg_product_mol,
                    reactant_2=arc_reaction.r_species[int(not reactants_reversed)],
                    h1=h1,
                    h2=h2,
                    c=c,
                    d=d,
                    r1_stretch=r1_stretch,
                    r2_stretch=r2_stretch,
                    a2=a2,
                    d2=d2,
                    d3=d3,
                    reactants_reversed=reactants_reversed,
                )
            except ValueError as e:
                logger.error(f'Could not generate a guess using Heuristics for H abstraction reaction, got:\n{e}')

In this code here, the list index out of range occurs. More specifically:

arc_reaction.r_species[int(not reactants_reversed)]

The int(not reactans_reversed) is evaluating to 1 (as it is False). However, the list in this instance has a len of 1, therefore, there is not [1].

Should we be then also adding to the except IndexError? @alongd @kfir4444

kfir4444 commented 1 year ago

@Laxzal Thanks! that is an impressive debugging! I think, however, that the arc_reaction.r_species should be a list of length 2, since it is an H_Abstraction reaction, so something else must be in play.

calvinp0 commented 1 year ago

@kfir4444 Great point!

So, looking at r_76_[S]S + r_76_[S]S <=> r_76_SS + r_76_[S][S], we have arc_reaction.r_species. And in this variable it only has one r species - 'r_76_[S]S'

alongd commented 1 year ago

If we have an H Abstraction reaction, but ARC only has 1 reactant or 1 product, we should't run heuristics TS search (or any other search)

Some thoughts: A. Why do we only have 1 reactant? Can you try to create an ARCReraction object for this reaction in a separate script and try to see what's going on? Then let's fix it and add a terst

B. We should check at the outset of the Heuristics method that we have 2 reactants and 2 products before calling the H Abstraction method

C. We could check that ANY reaction identified as having an RMG template actually has the number of reactants and products as the template demands. If it doesn't then output an error message, and perhaps don't process it?

alongd commented 1 year ago

I see now what @Laxzal wrote me offline: it's probably since the reactants are identical. In this case, we should change the code to refrain from calling the .r_species or .p_species attributes, and instead use the ARCReaction.get_reactants_and_products() method which returns the correct number of reactants and products

A similar fix was applied here: https://github.com/ReactionMechanismGenerator/ARC/pull/609