OpenFreeEnergy / gufe

grand unified free energy by OpenFE
https://gufe.readthedocs.io
MIT License
28 stars 8 forks source link

Convenient way extract components from `ChemicalSystem` #251

Open ijpulidos opened 10 months ago

ijpulidos commented 10 months ago

In the current implemented protocols that use gufe objects for alchemiscale, we find that we need ways to extract components from the ChemicalSystem. For example as in https://github.com/OpenFreeEnergy/openfe/blob/2af8dcda2921ccfa131456bb291453ca3c487dbb/openfe/protocols/openmm_utils/system_validation.py#L139

This raises the question of whether this utility function/method should be part of the ChemicalSystem object itself. It seems like a good candidate of a commonly used functionality that gufe could provide, and if the inner structure of how the ChemicalSystem object changes protocols don't have to keep track and adapt when this happens.

I think it could be desirable to have something like chemical_system.get_components(type=SomeComponentType). I'm raising this question here for further discussion.

richardjgowers commented 10 months ago

@ijpulidos yeah having ChemicalSystem.get_components_of_type(type: Component) -> list[Component] would work fine. Since the ChemicalSystem is just a dict[str, Component all this method would do is [c for c in cs.components.values() if isinstance(c, type)] but I guess it's a handy.

ijpulidos commented 10 months ago

Yes, I think it could be something that gufe could provide, and the complexity shouldn't be that hard, there might be a need to make some logic to make sure we are not returning a component more than once. I think since these are GufeTokenizable we should be able to use set operations for this, correct?

dotsdl commented 10 months ago

Possibly related to #144! Thanks @ijpulidos!