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

Update from comments for form and mult #549

Merged
merged 1 commit into from
Aug 13, 2024
Merged

Conversation

Rosalbam1
Copy link
Contributor

No description provided.

Copy link
Collaborator

@avcopan avcopan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! A few more edits!

"""Construct a string from Reaction Class.

:return: String from self
"""
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Edit:

    def __str__(self) -> str:
        """Convert a reaction class object to a string.
        
        :return: The reaction class string
        """


:return: _description_
:rtype: _type_
"""
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Edit:

    def __repr__(self) -> str:
        """Get a string literal describing the reaction class object.
        
        :return: The reaction class string literal
        """

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: __repr__() and __str__() are essentially the same, except that the first one is supposed to represent the object, whereas the second one is supposed to be the result of "converting the object to a string".

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first one gets called when you call repr(object), whereas the second one gets called when you call str(object).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Example:

>>> print(repr("abc"))
'abc'
>>> print(str("abc"))
abc

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The way we are using __repr__() above, simply returning the string literal, isn't really the intended usage, and I don't think it's really necessary. But I am hesitant to take it out because this class is tied in with some ugly higher-level code that is very bug-prone. Eventually, I would like to get rid of these classes entirely.

@@ -57,23 +65,19 @@ def reverse(cls, value: str):

@classmethod
def is_reversible(cls, value: str) -> bool:
"""Is this reaction class reversible?
"""Is this reaction class reversible?.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be consistent with the standard formatting that the linter wants, let's replace questions like these with condition al statements:

"""Whether this reaction class is reversible.

"""
return cls.reverse(value) is not None

@classmethod
def is_bimolecular(cls, value: str) -> bool:
"""Is this reaction class bimolecular?
"""Is this reaction class bimolecular?.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"""Whether this reaction class is bimolecular.

(See above)

@@ -86,12 +90,10 @@ def is_bimolecular(cls, value: str) -> bool:

@classmethod
def requires_spin_designation(cls, value: str) -> bool:
"""Is this a reaction class that requires a spin designation?
"""Is this a reaction class that requires a spin designation?.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"""Whether this reaction class requires a spin designation.

@@ -18,9 +18,10 @@
STOICH = pp.Opt(pp.Literal("*") | ppc.integer).setParseAction(lambda x: x if x else [1])
ATOM_COUNT = pp.Group(SYMBOL + STOICH)
FORMULA = pp.OneOrMore(ATOM_COUNT)
Formul = dict[str, int]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be Formula (throughout). You can do this using right-click and "Rename symbol" to update all instances.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise, the edits below look good.

@@ -173,7 +174,7 @@ def string(fml: dict[str:int], hyd: bool = True) -> str:
return fml_str


def string2(fml: dict[str:int]) -> str:
def string2(fml: Formul) -> str:
"""Convert formula dictionary to formula string that includes 1s in when
there is only one atom.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good up to this point. A few more edits for the functions below this point:

def from_string(...) -> Formula:
...
def sorted_symbols(...) -> tuple[str, ...]:
...
def sort_vector(fml: Formula, symbs: Sequence[str] | None = None) -> tuple[int, ...]:

def argsort_hydrogen_abstraction(
rct_fmls: Sequence[Formul], prd_fmls: Sequence[Formul]
) -> tuple[tuple[int, int], tuple[int, int]] | None:
"""Generate the indices which allows the reactants and products of
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.


from ._mult import spin as _spin


def high(rct_mults: tuple[float], prd_mults: tuple[float]) -> int:
def high(rct_mults: Sequence[float], prd_mults: Sequence[float]) -> int:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

@@ -18,7 +19,7 @@ def high(rct_mults: tuple[float], prd_mults: tuple[float]) -> int:
return min(_high(rct_mults), _high(prd_mults))


def low(rct_mults: tuple[float], prd_mults: tuple[float]) -> int:
def low(rct_mults: Sequence[float], prd_mults: Sequence[float]) -> int:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

@avcopan avcopan merged commit 9d7c667 into Auto-Mech:dev Aug 13, 2024
3 checks passed
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.

2 participants