-
Notifications
You must be signed in to change notification settings - Fork 49
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
Add PeriodicCollapser #313
Conversation
This pull request introduces 2 alerts when merging afa6da7 into 4dc93dd - view on LGTM.com new alerts:
|
This pull request introduces 2 alerts when merging 97858b2 into 4dc93dd - view on LGTM.com new alerts:
|
This pull request introduces 1 alert when merging 168a360 into 4dc93dd - view on LGTM.com new alerts:
|
), | ||
), | ||
) | ||
def unscaled_periodic_case(request): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a great example of when an inline comment would be helpful - the developer has no idea, without looking at the test, why this would be an unscaled test case...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. Yeah these test cases are meant to avoid using optimizers which edit the PeriodicInfo
. I think putting it into the docstring would work too, as it's essentially part of the interface. Unless you have a particular reason why you prefer inline for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Amazing work.
Co-authored by: @andrewtarzia
Issues addressed: #282, #278
This PR adds the following features:
Optimizer
,PeriodicCollapser
, which can be usedwith periodic COF topology graphs.
ConstructionResult
,called
PeriodicConstructionResult
, which additionallyholds periodic information about the constructed molecule.
ConstructedMolecule
,init_from_construction_result
. This newinitializer can be used when the user calls
TopologyGraph.construct()
directly, and means that theycan get the
ConstructionResult
and the correspondingConstructedMolecule
, without having to runconstruction twice.
This PR also deprecates the method
TopologyGraph.get_periodic_info()
,use
PeriodicConstructionResult.get_periodic_info()
instead.There were a couple of changes which needed to be made to add the
PeriodicCollapser
. The main issue was that thePeriodicCollapser
needs to be able to modify the lattice constants, so that the
PeriodicInfo
returned byPeriodicConstructionResult.get_periodic_info()
, has thelattice constants shrunk by the same amount the
ConstructedMolecule
is. In order to do this, theConstructionState
and
GraphState
were extended to allow modification of thelattice constants via
with_lattice_constants()
and retrieval of thelattice constants via
get_lattice_constants()
.The
PeriodicInfo
is now being returned by thePeriodicConstructionResult
rather than by theTopologyGraph
because it avoids needing to run the construction twice, if the
user wishes to get the
ConstructedMolecule
and thePeriodicInfo
. If thePeriodicInfo
was returned by theTopologyGraph
,TopologyGraph.get_periodic_info()
wouldhave to run a construction. This is because it is only after the
construction that the value by which the
PeriodicInfo
should be shrunk by is known. If the user wishes to get both
the
PeriodicInfo
and theConstructedMolecule
in one go,they can call
TopologyGraph.construct()
explicitly.There is an important design concept this PR highlighted.
The return value of
TopologyGraph.construct
returns theConstructionResult
which holds the data necessary to createa
ConstructedMolecule
, but also additional data which does notbelong on the
ConstructedMolecule
,PeriodicInfo
is anexample of that.
ConstructionResult
can be subclassed, asin
PeriodicConstructionResult
, if the additional data is specificto some subset of
TopologyGraph
classes. The importance ofhaving both
ConstructedMolecule
andConstructionResult
isthat you can do very general things with a
ConstructedMolecule
,such as serialization, which you cannot do with a
ConstructionResult
. However,ConstructionResult
may holdspecific data which you cannot find on a
ConstructedMolecule
.So one is generic while the other is specific, and this means each
has different use cases. By allowing the conversion from
ConstructionResult
toConstructedMolecule
, the user can usewhatever fits their use case.
The
ConstructionState
,ConstructionResult
andGraphState
classes have the method
get_num_building_block()
andget_building_blocks()
added. This was necessary so thatConstructedMolecule.init_from_construction_result()
can beinitialized from
ConstructionResult
only, rather than bothConstructionResult
andTopologyGraph
. TheConstructedMolecule
needs to create the_num_building_blocks
attribute, for which it needs to call
get_num_building_block()
and
get_building_blocks()
. Previously these were found on theTopologyGraph
only, but now I'm moving them into theConstructionResult
too. Having to initialize from both aConstructionResult
andTopologyGraph
is bad becausethere is no guarantee that the
ConstructionResult
was producedby the
TopologyGraph
you pass in as the argument.I considered replacing
get_building_blocks()
andget_num_building_block()
, with a single method,get_num_building_blocks()
, which would return adict
which mapseach building block to the number of times it appears in the
ConstructedMolecule
. However, I decided against this becausethe API
get_building_block()
andget_num_building_block
alreadyexists on
TopologyGraph
andConstructedMolecule
, so this keepsthe APIs of
ConstructionState
,ConstructionResult
andGraphState
consistent. In addition, the order of building blocks is important,
and while
dict
instances are ordered, having aget_building_blocks()
method makes the importance of ordering more clear, and easier to
document, in my opinion.