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

Give example of subclassing MoleculeRecord #415

Open
lukasturcani opened this issue Jan 12, 2022 · 0 comments
Open

Give example of subclassing MoleculeRecord #415

lukasturcani opened this issue Jan 12, 2022 · 0 comments

Comments

@lukasturcani
Copy link
Owner

lukasturcani commented Jan 12, 2022

A use-case of the EA should be extending it with functionality specific to certain topology graphs. For example, it could be useful to subclass a MoleculeRecord to allow mutation and crossover operations specifically for Lineartopology graphs.

class LinearMoleculeRecord(MoleculeRecord):
    def __init__(
        self,
        first: BuildingBlock,
        second: BuildingBlock,
        third: BuildingBlock,
    ) -> None:
    
        MoleculeRecord.__init__(
            topology_graph=stk.polymer.Linear(
                 building_blocks=(first, second, third),
                 repeating_unit="ABC",
                num_repeating_units=8,
            )
        )
        self._first = first
       self._second = second
        self._third = third

    def get_first(self) -> BuildingBlock:
        return self._first

    def get_second(self) -> BuildingBlock:
        return self._second

    def get_third(self) -> BuildingBlock:
        return self._third


class MyLinearMutator:
    def __init__(self, name: str) -> None:
        self._name = name

    def mutate(self, record: LinearMoleculeRecord) -> MutationRecord:
         # change the first building block to something else
         return MutationRecord(
               molecule_record=LinearMoleculeRecord(
                      first=stk.BuildingBlock('BrCCCCCCBr', [stk.BromoFactory()]),
                      second=record.get_second(),
                      third=record.get_third()
                )  
                mutator_name=self._name,  
            )  
         )

cc: @stevenkbennett

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

No branches or pull requests

1 participant