Covalent Organic Framework
- class Cof(building_blocks, lattice_size, periodic=False, vertex_alignments=None, reaction_factory=GenericReactionFactory(), num_processes=1, optimizer=<stk.molecular.topology_graphs.topology_graph.optimizers.null.NullOptimizer object>)[source]
Bases:
stk.molecular.topology_graphs.topology_graph.topology_graph.topology_graph.TopologyGraph
Represents a COF topology graph.
Notes
COF topologies are added by creating a subclass, which defines the
_vertex_prototypes
and_edge_prototypes
class attributes.Examples
Subclass Implementation
The source code of the subclasses, listed in
cof
, can serve as good examples.Basic Construction
Cof
instances can be made by providing the building block molecules and lattice size only (usingHoneycomb
as an example)import stk bb1 = stk.BuildingBlock('BrCCBr', [stk.BromoFactory()]) bb2 = stk.BuildingBlock('BrCC(CBr)CBr', [stk.BromoFactory()]) cof = stk.ConstructedMolecule( topology_graph=stk.cof.Honeycomb((bb1, bb2), (3, 3, 1)), )
Suggested Optimization
For
Cof
topologies, it is recommend to use theCollapser
optimizer if using the nonperiodic form. For periodic systems, thePeriodicCollapser
is recommended.import stk bb1 = stk.BuildingBlock('BrCCBr', [stk.BromoFactory()]) bb2 = stk.BuildingBlock('BrCC(CBr)CBr', [stk.BromoFactory()]) # Nonperiodic. cof = stk.ConstructedMolecule( topology_graph=stk.cof.Honeycomb( building_blocks=(bb1, bb2), lattice_size=(3, 3, 1), # Setting scale_steps to False tends to lead to a # better structure. optimizer=stk.Collapser(scale_steps=False), ), ) # Periodic. cof = stk.ConstructedMolecule( topology_graph=stk.cof.PeriodicHoneycomb( building_blocks=(bb1, bb2), lattice_size=(3, 3, 1), optimizer=stk.PeriodicCollapser(), ), )
Accessing the Periodic Information
When building periodic
Cof
instances, the periodic information, such as the unit cell, can be accessed if you use thePeriodicConstructionResult
returned by callingCof.construct()
import stk bb1 = stk.BuildingBlock('BrCCBr', [stk.BromoFactory()]) bb2 = stk.BuildingBlock('BrCC(CBr)CBr', [stk.BromoFactory()]) topology_graph = stk.cof.PeriodicHoneycomb( building_blocks=(bb1, bb2), lattice_size=(3, 3, 1), ) construction_result = topology_graph.construct() cof = stk.ConstructedMolecule.init_from_construction_result( construction_result=construction_result, ) periodic_info = construction_result.get_periodic_info() cell_matrix = periodic_info.get_cell_matrix() # Can access all unit-cell parameters. a = periodic_info.get_a() b = periodic_info.get_b() c = periodic_info.get_c() alpha = periodic_info.get_alpha() beta = periodic_info.get_beta() gamma = periodic_info.get_gamma() # Write to .pdb file. writer = stk.PdbWriter() writer.write( molecule=cof, path='cof.pdb', periodic_info=periodic_info, )
Structural Isomer Construction
Different structural isomers of COFs can be made by using the vertex_alignments optional parameter
import stk bb1 = stk.BuildingBlock('BrCCBr', [stk.BromoFactory()]) bb2 = stk.BuildingBlock('BrCC(CBr)CBr', [stk.BromoFactory()]) cof2 = stk.ConstructedMolecule( topology_graph=stk.cof.Honeycomb( building_blocks=(bb1, bb2), lattice_size=(3, 3, 1), vertex_alignments={0: 2, 1: 1, 2: 1}, ), )
The parameter maps the id of a vertex to a number between 0 (inclusive) and the number of edges the vertex is connected to (exclusive). So a vertex connected to three edges can be mapped to
0
,1
or2
.By changing which edge each vertex is aligned with, a different structural isomer of the COF can be formed.
Multi-Building Block COF Construction
You can also build COFs with multiple building blocks, but, if you have multiple building blocks with the same number of functional groups, you have to assign each building block to the vertex you want to place it on
import stk bb1 = stk.BuildingBlock('BrCCBr', [stk.BromoFactory()]) bb2 = stk.BuildingBlock('BrCNCBr', [stk.BromoFactory()]) bb3 = stk.BuildingBlock('BrCC(CBr)CBr', [stk.BromoFactory()]) bb4 = stk.BuildingBlock('BrCC(NCBr)CBr', [stk.BromoFactory()]) cof = stk.ConstructedMolecule( topology_graph=stk.cof.Honeycomb( # building_blocks is now a dict, which maps building # blocks to the id of the vertices it should be placed # on. You can use ranges to specify the ids. building_blocks={ bb1: (2, 4, 7, 8, 9, 12, 13, 14, 17, 18, 19), bb2: 3, bb3: (0, 10, 11, 15, 16), bb4: (1, 5, 6), }, lattice_size=(2, 2, 1), ), )
You can combine this with the vertex_alignments parameter
cof2 = stk.ConstructedMolecule( topology_graph=stk.cof.Honeycomb( building_blocks={ bb1: (2, 4, 7, 8, 9, 12, 13, 14, 17, 18, 19), bb2: 3, bb3: (0, 10, 11, 15, 16), bb4: (1, 5, 6), }, lattice_size=(2, 2, 1), vertex_alignments={0: 2, 1: 1, 2: 1}, ), )
Methods
clone
()Return a clone.
Construct a
ConstructedMolecule
.Yield the building blocks.
get_num_building_block
(building_block)Get the number of times building_block is present.
with_building_blocks
(building_block_map)Return a clone holding different building blocks.
- __init__(building_blocks, lattice_size, periodic=False, vertex_alignments=None, reaction_factory=GenericReactionFactory(), num_processes=1, optimizer=<stk.molecular.topology_graphs.topology_graph.optimizers.null.NullOptimizer object>)[source]
Initialize a
Cof
instance.- Parameters
building_blocks (
tuple
ordict
) –Can be a
tuple
ofBuildingBlock
instances, which should be placed on the topology graph.Can also be a
dict
which maps theBuildingBlock
instances to the ids of the vertices it should be placed on. Adict
is required when there are multiple building blocks with the same number of functional groups, because in this case the desired placement is ambiguous.lattice_size (
tuple
ofint
) – The size of the lattice in the x, y and z directions.periodic (
bool
, optional) – Toggle the construction of a periodic molecule. IfTrue
, periodic bonds will be made across the edges of the lattice.vertex_alignments (
dict
, optional) – A mapping from the id of aVertex
to anEdge
connected to it. TheEdge
is used to align the firstFunctionalGroup
of aBuildingBlock
placed on that vertex. Only vertices which need to have their default edge changed need to be present in thedict
. IfNone
then the default edge is used for each vertex. Changing whichEdge
is used will mean that the topology graph represents different structural isomers. The edge is referred to by a number between0
(inclusive) and the number of edges the vertex is connected to (exclusive).reaction_factory (
ReactionFactory
, optional) – The reaction factory to use for creating bonds between building blocks.num_processes (
int
, optional) – The number of parallel processes to create duringconstruct()
.optimizer (
Optimizer
, optional) – Used to optimize the structure of the constructed molecule.
- Raises
AssertionError – If the any building block does not have a valid number of functional groups.
ValueError – If the there are multiple building blocks with the same number of functional_groups in building_blocks, and they are not explicitly assigned to vertices. The desired placement of building blocks is ambiguous in this case.
UnoccupiedVertexError – If a vertex of the COF topology graph does not have a building block placed on it.
OverlyOccupiedVertexError – If a vertex of the COF topology graph has more than one building block placed on it.
- construct()[source]
Construct a
ConstructedMolecule
.- Returns
The data describing the
ConstructedMolecule
.- Return type
- get_building_blocks()
Yield the building blocks.
Building blocks are yielded in an order based on their position in the topology graph. For two equivalent topology graphs, but with different building blocks, equivalently positioned building blocks will be yielded at the same time.
- Yields
A building block of the topology graph.
- Return type
- get_num_building_block(building_block)
Get the number of times building_block is present.
- Parameters
building_block (
BuildingBlock
) – The building block whose frequency in the topology graph is desired.- Return type
- Returns
The number of times building_block is present in the topology graph.
- with_building_blocks(building_block_map)
Return a clone holding different building blocks.
- Parameters
building_block_map (
dict
[BuildingBlock
,BuildingBlock
]) – Maps a building block in the current topology graph to the building block which should replace it in the clone. If a building block should be not replaced in the clone, it can be omitted from the map.- Return type
- Returns
The clone.