Skip to content

'Fragment' object has no attribute 'is_atom_in_cycle' error#2400

Merged
hwpang merged 4 commits intomainfrom
frag_err_2
Mar 21, 2023
Merged

'Fragment' object has no attribute 'is_atom_in_cycle' error#2400
hwpang merged 4 commits intomainfrom
frag_err_2

Conversation

@alongd
Copy link
Copy Markdown
Member

@alongd alongd commented Mar 15, 2023

Related to #2395

Another issue with the Fragment class was encountered. It takes time for these errors to pop (in my experience, only in an advanced stage of an RMG run after a few hundred species were added into the core).

I got the following trace:

Traceback (most recent call last):
  File "/home/alongd/Code/RMG-Py/rmg.py", line 112, in main
    rmg.execute(**kwargs)
  File "/home/alongd/Code/RMG-Py/rmgpy/rmg/main.py", line 944, in execute
    self.reaction_model.enlarge(objectToEnlarge)
  File "/home/alongd/Code/RMG-Py/rmgpy/rmg/model.py", line 709, in enlarge
    self.update_unimolecular_reaction_networks()
  File "/home/alongd/Code/RMG-Py/rmgpy/rmg/model.py", line 1918, in update_unimolecular_reaction_networks
    network.update(self, self.pressure_dependence)
  File "/home/alongd/Code/RMG-Py/rmgpy/rmg/pdep.py", line 808, in update
    spec.generate_statmech()
  File "rmgpy/species.py", line 821, in rmgpy.species.Species.generate_statmech
  File "/home/alongd/Code/RMG-Py/rmgpy/data/statmech.py", line 679, in get_statmech_data
    statmech_model = self.get_statmech_data_from_groups(molecule, thermo_model)
  File "/home/alongd/Code/RMG-Py/rmgpy/data/statmech.py", line 713, in get_statmech_data_from_groups
    return self.groups['groups'].get_statmech_data(molecule, thermo_model)
  File "/home/alongd/Code/RMG-Py/rmgpy/data/statmech.py", line 388, in get_statmech_data
    group_count = self.get_frequency_groups(molecule)
  File "/home/alongd/Code/RMG-Py/rmgpy/data/statmech.py", line 342, in get_frequency_groups
    if molecule.is_atom_in_cycle(atom):
AttributeError: 'Fragment' object has no attribute 'is_atom_in_cycle'

I'm not fluent in the purpose of the Fragment object, and one of the questions to be asked is whether the behavior that we see (here and in the previous PR) that a call inside statmech.py of molecule.is_atom_in_cycle(atom) is treating a Fragment instance instead of a Molecule instance is desired. Perhaps Fragment objects are not supposed to be processed by statmech at all? If so, then we need a more fundamental fix rather than these patches.
(I didn't specifically asked in the input file to use fragments)

This patch PR addresses the specific error in the above trace. We may encounter additional similar instances in the future since the Fragment class by design does not implement all the methods of the Molecule object. Perhaps a possible solution would be to inherit from Molecule instead of from Graph? E.g., class Fragment(Molecule)? I don't feel I have a thorough understanding of the Fragment object though to go ahead and implement this.

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 16, 2023

Codecov Report

Merging #2400 (135f28d) into main (5149ade) will increase coverage by 0.04%.
The diff coverage is 93.33%.

@@            Coverage Diff             @@
##             main    #2400      +/-   ##
==========================================
+ Coverage   48.24%   48.29%   +0.04%     
==========================================
  Files         110      110              
  Lines       30626    30649      +23     
  Branches     7986     7995       +9     
==========================================
+ Hits        14776    14802      +26     
+ Misses      14306    14304       -2     
+ Partials     1544     1543       -1     
Impacted Files Coverage Δ
rmgpy/molecule/fragment.py 73.50% <75.00%> (+0.39%) ⬆️
rmgpy/molecule/fragment_test.py 98.29% <96.15%> (+1.10%) ⬆️

... and 2 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@alongd alongd requested review from kspieks and lily90502 March 17, 2023 05:02
@lily90502
Copy link
Copy Markdown
Contributor

I agree that inherit from Molecule is easier for maintainability. We have this separate PR addressing this issue #2360
We will keep working on this!

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

Successfully merging this pull request may close these issues.

3 participants