Пример #1
0
def check_edge_functional_groups(
    old_state,
    new_state,
    building_blocks,
    placement_results,
):
    expected = get_expected_edge_functional_groups(
        old_state=old_state,
        building_blocks=building_blocks,
        placement_results=placement_results,
    )

    for edge_id in range(old_state.get_num_edges()):
        edge_group = stk.EdgeGroup((old_state.get_edge(edge_id), ))
        expected_fgs = {get_fg_key(fg): fg for fg in expected[edge_id]}
        new_state_fgs = {
            get_fg_key(fg): fg
            for fg
            in new_state.get_edge_group_functional_groups(edge_group)
        }
        assert expected_fgs.keys() == new_state_fgs.keys()
        for fg_key in expected_fgs:
            is_equivalent_fg(
                fg1=expected_fgs[fg_key],
                fg2=new_state_fgs[fg_key],
            )
Пример #2
0
def two_two_reaction(
    periodicity,
    functional_group2,
    functional_group2_2,
    bond_order,
):
    bond_order_key = frozenset({
        type(functional_group2),
        type(functional_group2_2),
    })
    position_matrix = get_position_matrix(
        functional_group1=functional_group2,
        functional_group2=functional_group2_2,
    )
    edge = MockEdge(0, periodicity)
    return CaseData(
        factory=stk.GenericReactionFactory(
            bond_orders={
                bond_order_key: bond_order,
            },
        ),
        construction_state=MockConstructionState(
            edges=(edge, ),
            edge_functional_groups={
                0: (
                    functional_group2,
                    functional_group2_2,
                ),
            },
            position_matrix=position_matrix,
        ),
        edge_group=stk.EdgeGroup(
            edges=(edge, ),
        ),
        reaction_result=ReactionResult(
            new_atoms=(),
            new_bonds=get_new_bonds(
                functional_group1=functional_group2,
                functional_group2=functional_group2_2,
                order=bond_order,
                periodicity=periodicity,
            ),
            deleted_atoms=it.chain(
                functional_group2.get_deleters(),
                functional_group2_2.get_deleters(),
            ),
            deleted_bonds=(),
        ),
    )
Пример #3
0
def dative_reaction(
    functional_group1,
    functional_group1_2,
    periodicity,
    bond_order,
):
    bond_order_key = frozenset({
        type(functional_group1),
        type(functional_group1_2),
    })
    edge = MockEdge(0, periodicity)
    return CaseData(
        factory=stk.DativeReactionFactory(
            stk.GenericReactionFactory(
                bond_orders={
                    bond_order_key: bond_order,
                },
            )
        ),
        construction_state=MockConstructionState(
            edges=(edge, ),
            edge_functional_groups={
                0: (
                    functional_group1,
                    functional_group1_2,
                )
            }
        ),
        edge_group=stk.EdgeGroup(
            edges=(edge, )
        ),
        reaction_result=ReactionResult(
            new_atoms=(),
            new_bonds=get_new_bonds(
                functional_group1=functional_group1,
                functional_group2=functional_group1_2,
                order=bond_order,
                periodicity=periodicity,
            ),
            deleted_atoms=it.chain(
                functional_group1.get_deleters(),
                functional_group1_2.get_deleters(),
            ),
            deleted_bonds=(),
        ),
    )
def get_expected_edge_functional_groups(
    old_state,
    building_blocks,
    placement_results,
):
    expected = defaultdict(list)
    for edge_id in range(old_state.get_num_edges()):
        edge_group = stk.EdgeGroup((old_state.get_edge(edge_id), ))
        expected[edge_id].extend(
            old_state.get_edge_group_functional_groups(edge_group))
    for edge_id, fg in added_functional_groups(
            old_state=old_state,
            building_blocks=building_blocks,
            placement_results=placement_results,
    ):
        expected[edge_id].append(fg)
    return expected
Пример #5
0
def is_clone(construction_state, clone):
    atoms = it.zip_longest(
        construction_state.get_atoms(),
        clone.get_atoms(),
    )
    for atom1, atom2 in atoms:
        assert atom1 is atom2

    bonds = it.zip_longest(
        construction_state.get_bonds(),
        clone.get_bonds(),
    )
    for bond1, bond2 in bonds:
        assert bond1 is bond2

    atom_infos = it.zip_longest(
        construction_state.get_atom_infos(),
        clone.get_atom_infos(),
    )
    for atom_info1, atom_info2 in atom_infos:
        assert atom_info1 is atom_info2

    bond_infos = it.zip_longest(
        construction_state.get_bond_infos(),
        clone.get_bond_infos(),
    )
    for bond_info1, bond_info2 in bond_infos:
        assert bond_info1 is bond_info2

    assert (construction_state.get_num_vertices() == clone.get_num_vertices())

    for vertex_id in range(clone.get_num_vertices()):
        assert (construction_state.get_vertex(vertex_id) is
                clone.get_vertex(vertex_id))

    assert np.all(
        np.equal(
            construction_state.get_position_matrix(),
            clone.get_position_matrix(),
        ))

    assert construction_state.get_num_edges() == clone.get_num_edges()
    for edge_id in range(clone.get_num_edges()):
        assert (construction_state.get_edge(edge_id) is
                clone.get_edge(edge_id))

    edge_group = stk.EdgeGroup(edges=map(clone.get_edge,
                                         range(clone.get_num_edges())), )
    functional_groups = it.zip_longest(
        construction_state.get_edge_group_functional_groups(
            edge_group=edge_group, ),
        clone.get_edge_group_functional_groups(edge_group),
    )
    for fg1, fg2 in functional_groups:
        assert fg1 is fg2

    counts1 = construction_state.get_building_block_counts()
    counts2 = clone.get_building_block_counts()
    assert (counts1.keys() | counts2.keys()) == counts1.keys()
    for building_block, count1 in counts1.items():
        assert count1 == counts2[building_block]

    assert all(
        np.all(np.equal(actual_constant, expected_constant))
        for actual_constant, expected_constant in it.zip_longest(
            construction_state.get_lattice_constants(),
            clone.get_lattice_constants(),
        ))