Esempio n. 1
0
def get_case_data_1() -> CaseData:
    return CaseData(
        molecule=stk.BuildingBlock(
            smiles='Br[C+2][N+]Cl',
            functional_groups=[stk.BromoFactory()],
            placer_ids=(0, ),
        ),
        result=stk.BuildingBlock.init(
            atoms=(
                stk.Cl(0),
                stk.Br(1),
                stk.C(2, 2),
                stk.N(3, 1),
            ),
            bonds=(
                stk.Bond(stk.Cl(0), stk.N(3, 1), 1),
                stk.Bond(stk.Br(1), stk.C(2, 2), 1),
                stk.Bond(stk.C(2, 2), stk.N(3, 1), 1),
            ),
            position_matrix=np.array([
            ]),
            functional_groups=(
                stk.Bromo(
                    bromine=stk.Br(1),
                    atom=stk.C(2, 2),
                    bonders=(stk.C(2, 2), ),
                    deleters=(stk.Br(1), ),
                ),
            ),
            placer_ids=(1, ),
        )
    )
Esempio n. 2
0
def bond(hydrogen, carbon):
    return stk.Bond(atom1=hydrogen,
                    atom2=carbon,
                    order=2,
                    attr1=1,
                    attr2='2',
                    _attr3=12.2)
Esempio n. 3
0
def periodic_bond(lithium, chlorine):
    return stk.Bond(atom1=lithium,
                    atom2=chlorine,
                    order=21,
                    periodicity=(1, 0, -1),
                    attr10=16,
                    attr20='26',
                    _attr30=126.2)
Esempio n. 4
0
def get_new_bonds(
    functional_group1,
    functional_group2,
    order,
    periodicity,
):
    bonder1, bonder2 = functional_group1.get_bonders()
    bonder3, bonder4 = functional_group2.get_bonders()
    yield stk.Bond(
        atom1=bonder1,
        atom2=bonder3,
        order=order,
        periodicity=periodicity,
    )
    yield stk.Bond(
        atom1=bonder2,
        atom2=bonder4,
        order=order,
        periodicity=periodicity,
    )
Esempio n. 5
0
def get_new_bonds(
    functional_group1,
    functional_group2,
    order,
    periodicity,
):
    fg1_bonder = next(functional_group1.get_bonders())
    fg2_bonders = functional_group2.get_bonders()
    yield stk.Bond(
        atom1=fg1_bonder,
        atom2=next(fg2_bonders),
        order=order,
        periodicity=periodicity,
    )
    yield stk.Bond(
        atom1=fg1_bonder,
        atom2=next(fg2_bonders),
        order=order,
        periodicity=periodicity,
    )
Esempio n. 6
0
def get_new_bonds(
    functional_group1,
    functional_group2,
    order,
    periodicity,
):
    yield stk.Bond(
        atom1=next(functional_group1.get_bonders()),
        atom2=next(functional_group2.get_bonders()),
        order=order,
        periodicity=periodicity,
    )
Esempio n. 7
0
def get_bond(
    functional_group1,
    functional_group2,
    bond_order,
    periodicity,
):
    return stk.Bond(
        atom1=next(functional_group1.get_bonders()),
        atom2=next(functional_group2.get_bonders()),
        order=bond_order,
        periodicity=periodicity,
    )
Esempio n. 8
0
def get_bonds(
    functional_group1,
    functional_group2,
    bond_order,
    periodicity,
):
    b1, b2 = functional_group1.get_bonders()
    b3, b4 = functional_group2.get_bonders()
    yield stk.Bond(
        atom1=b1,
        atom2=b3,
        order=bond_order,
        periodicity=periodicity,
    )

    yield stk.Bond(
        atom1=b2,
        atom2=b4,
        order=bond_order,
        periodicity=periodicity,
    )
Esempio n. 9
0
def case_data(atom1, atom2, order, periodicity):
    """
    A :class:`.CaseData` instance.

    """

    return CaseData(
        bond=stk.Bond(atom1, atom2, order, periodicity),
        atom1=atom1,
        atom2=atom2,
        order=order,
        periodicity=periodicity,
    )
Esempio n. 10
0
    def transform(self, molecule):
        """
        Transform a molecule.

        Parameters
        ----------
        molecule : :class:`stk.Molecule`
            Molecule to modify.

        Returns
        -------
        molecule : :class:`stk.BuildingBlock`
            The resulting molecule.

        """

        rdkit_mol = molecule.to_rdkit_mol()
        rdkit.SanitizeMol(rdkit_mol)

        atoms = []
        for a in molecule.get_atoms():
            if isinstance(a, Du):
                atoms.append(
                    stk.Atom(
                        id=a.get_id(),
                        atomic_number=self._replacer.get_atomic_number(),
                        charge=self._replacer.get_charge(),
                    ))
            else:
                atoms.append(a)
        atoms = tuple(atoms)

        bonds = tuple(
            stk.Bond(
                atom1=atoms[b.get_atom1().get_id()],
                atom2=atoms[b.get_atom2().get_id()],
                order=b.get_order(),
            ) for b in molecule.get_bonds())
        position_matrix = molecule.get_position_matrix()
        building_block = stk.BuildingBlock.init(
            atoms=atoms,
            bonds=bonds,
            position_matrix=position_matrix,
        )
        building_block = stk.BuildingBlock.init_from_molecule(
            molecule=building_block,
            functional_groups=self._functional_groups,
        )

        return building_block
Esempio n. 11
0
def get_bond(
    functional_group1,
    functional_group2,
    bond_order,
    periodicity,
):

    bonder1, = functional_group1.get_bonders()
    bonder2, = functional_group2.get_bonders()

    if is_metal(bonder1):
        return stk.Bond(
            atom1=bonder2,
            atom2=bonder1,
            order=bond_order,
            periodicity=periodicity,
        )
    else:
        return stk.Bond(
            atom1=bonder1,
            atom2=bonder2,
            order=bond_order,
            periodicity=periodicity,
        )
Esempio n. 12
0
def get_new_bonds(
    functional_group1,
    functional_group2,
    order,
    periodicity,
):

    bonder1, = functional_group1.get_bonders()
    bonder2, = functional_group2.get_bonders()

    if is_metal(bonder1):
        yield stk.Bond(
            atom1=bonder2,
            atom2=bonder1,
            order=order,
            periodicity=periodicity,
        )
    else:
        yield stk.Bond(
            atom1=bonder1,
            atom2=bonder2,
            order=order,
            periodicity=periodicity,
        )
Esempio n. 13
0
def get_bonds(
    functional_group1,
    functional_group2,
    bond_order,
    periodicity,
):
    bonders1 = functional_group1.get_bonders()
    bonders2 = functional_group2.get_bonders()
    for bonder1, bonder2 in it.product(bonders1, bonders2):
        yield stk.Bond(
            atom1=bonder1,
            atom2=bonder2,
            order=bond_order,
            periodicity=periodicity,
        )
Esempio n. 14
0
import pytest
import stk

from .case_data import CaseData


@pytest.fixture(
    params=(CaseData(
        molecule=stk.BuildingBlock('NCCN'),
        bonds=(
            stk.Bond(stk.N(0), stk.C(1), 1),
            stk.Bond(stk.C(1), stk.C(2), 1),
            stk.Bond(stk.C(2), stk.N(3), 1),
            stk.Bond(stk.N(0), stk.H(4), 1),
            stk.Bond(stk.N(0), stk.H(5), 1),
            stk.Bond(stk.C(1), stk.H(6), 1),
            stk.Bond(stk.C(1), stk.H(7), 1),
            stk.Bond(stk.C(2), stk.H(8), 1),
            stk.Bond(stk.C(2), stk.H(9), 1),
            stk.Bond(stk.N(3), stk.H(10), 1),
            stk.Bond(stk.N(3), stk.H(11), 1),
        ),
    ), ), )
def case_data(request):
    return request.param
Esempio n. 15
0
from .case_data import CaseData
# Fixtures need to be visible for lazy_fixture() calls.
from .fixtures import *  # noqa


@pytest.fixture(
    params=[
        stk.BuildingBlock.init(
            atoms=(stk.C(0, 4), ),
            bonds=(),
            position_matrix=np.array([[0.0, 0.0, 0.0]]),
            functional_groups=(),
        ),
        stk.BuildingBlock.init(
            atoms=(stk.C(0, 3), stk.H(1)),
            bonds=(stk.Bond(stk.C(0, 3), stk.H(1), 1), ),
            position_matrix=np.array([
                [0.39382080513175644, 0.0, 0.0],
                [-0.39382080513175644, 0.0, 0.0],
            ]),
            functional_groups=(),
        ),
        stk.BuildingBlock.init(
            atoms=(stk.C(0, 2), stk.H(1), stk.H(2)),
            bonds=(
                stk.Bond(stk.C(0, 2), stk.H(1), 1),
                stk.Bond(stk.C(0, 2), stk.H(2), 1),
            ),
            position_matrix=np.array([
                [-0.002271396061231665, 0.034037398527897535, -0.0],
                [-1.0494595365731274, -0.017073891221884126, -0.0],
Esempio n. 16
0
import pytest
import numpy as np
import stk

from ..case_data import CaseData


@pytest.fixture(
    scope='session',
    params=(
        lambda: CaseData(
            building_block=stk.BuildingBlock.init(
                atoms=(stk.Br(0), stk.C(1, 2), stk.C(2, 2), stk.Br(3)),
                bonds=(
                    stk.Bond(stk.Br(0), stk.C(1, 2), 1),
                    stk.Bond(stk.C(1, 2), stk.C(2, 2), 1),
                    stk.Bond(stk.C(2, 2), stk.Br(3), 1),
                ),
                position_matrix=np.array([
                    [0., 0., 0.],
                    [1., 1., 1.],
                    [2., 2., 2.],
                    [3., 3., 3.],
                ]),
            ),
            functional_groups=(),
            core_atom_ids=(0, 1, 2, 3),
            placer_ids=(0, 1, 2, 3),
        ),
        lambda: CaseData(
            building_block=stk.BuildingBlock.init(
Esempio n. 17
0
    def split(self, molecule):
        """
        Split a molecule.

        Parameters
        ----------
        molecule : :class:`stk.Molecule`
            Molecule to modify.

        Returns
        -------
        molecules : :class:`iterable` of :class:`stk.BuildingBlock`
            The resulting list of molecules.

        """

        rdkit_mol = molecule.to_rdkit_mol()
        rdkit.SanitizeMol(rdkit_mol)
        bond_pair_ids_to_delete = []
        reactable_atom_ids = []
        for atom_ids in rdkit_mol.GetSubstructMatches(
                query=rdkit.MolFromSmarts(self._breaker_smarts)):
            # Get the atom ids of the query on either end of the broken
            # bond, translated from query ids to molecule atom ids.
            translated_bond_atom_ids = (
                atom_ids[self._bond_deleter_ids[0]],
                atom_ids[self._bond_deleter_ids[1]],
            )
            # Get tuples of the bonds to break by atom ids.
            bond_pair_ids_to_delete.extend(
                tuple(sorted((i, j)))
                for i, j in combinations(translated_bond_atom_ids, 2))
            # Get the atom ids of the atoms on either end of the broken
            # bond at which reactions can occur.
            reactable_atom_ids.extend(i for i in translated_bond_atom_ids)

        # Get the rdkit molecule bond ids associated with the bonds to
        # delete.
        bond_ids_to_delete = []
        for bond in rdkit_mol.GetBonds():
            idxs = tuple(sorted(
                (bond.GetBeginAtomIdx(), bond.GetEndAtomIdx())))
            if idxs in bond_pair_ids_to_delete:
                bond_ids_to_delete.append(bond.GetIdx())

        # Delete bonds and atoms.
        fragments = rdkit.GetMolFrags(
            rdkit.FragmentOnBonds(
                mol=rdkit_mol,
                bondIndices=tuple(bond_ids_to_delete),
                addDummies=True,
            ),
            asMols=True,
        )

        molecules = []
        for frag in fragments:
            atoms = []
            for a in frag.GetAtoms():
                if a.GetAtomicNum() == 0:
                    atoms.append(Du(a.GetIdx()))
                else:
                    atoms.append(
                        stk.Atom(
                            id=a.GetIdx(),
                            atomic_number=a.GetAtomicNum(),
                            charge=a.GetFormalCharge(),
                        ))
            atoms = tuple(atoms)

            bonds = tuple(
                stk.Bond(atom1=atoms[b.GetBeginAtomIdx()],
                         atom2=atoms[b.GetEndAtomIdx()],
                         order=(9 if b.GetBondType() == rdkit.BondType.
                                DATIVE else b.GetBondTypeAsDouble()))
                for b in frag.GetBonds())
            position_matrix = frag.GetConformer().GetPositions()
            molecules.append(
                stk.BuildingBlock.init(
                    atoms=atoms,
                    bonds=bonds,
                    position_matrix=position_matrix,
                ))

        return molecules
Esempio n. 18
0
 params=(
     lambda: CaseData(
         molecule=stk.BuildingBlock(
             smiles='Br[C+2][N+]Cl',
             functional_groups=[stk.BromoFactory()],
             placer_ids=(0, ),
         ),
         result=stk.BuildingBlock.init(
             atoms=(
                 stk.Cl(0),
                 stk.Br(1),
                 stk.C(2, 2),
                 stk.N(3, 1),
             ),
             bonds=(
                 stk.Bond(stk.Cl(0), stk.N(3, 1), 1),
                 stk.Bond(stk.Br(1), stk.C(2, 2), 1),
                 stk.Bond(stk.C(2, 2), stk.N(3, 1), 1),
             ),
             position_matrix=np.array([
             ]),
             functional_groups=(
                 stk.Bromo(
                     bromine=stk.Br(1),
                     atom=stk.C(2, 2),
                     bonders=(stk.C(2, 2), ),
                     deleters=(stk.Br(1), ),
                 ),
             ),
             placer_ids=(1, ),
         )
Esempio n. 19
0
import pytest
import stk

from .case_data import CaseData


@pytest.fixture(
    params=(
        stk.Bond(stk.C(0), stk.N(1), 1),
    ),
)
def bond(request):
    """
    A :class:`.Bond` instance.

    """

    return request.param


@pytest.fixture(
    params=(
        stk.BuildingBlock('NCCN'),
        None,
    ),
)
def building_block(request):
    """
    A valid building block for a :class:`.BondInfo`.

    """
Esempio n. 20
0
import pytest

import stk

from .case_data import CaseData


@pytest.fixture(
    params=(stk.Bond(stk.C(0), stk.N(1), 1), ), )
def bond(request):
    """
    A :class:`.Bond` instance.

    """

    return request.param


@pytest.fixture(
    params=(
        stk.BuildingBlock('NCCN'),
        None,
    ), )
def building_block(request):
    """
    A valid building block for a :class:`.BondInfo`.

    """

    return request.param
Esempio n. 21
0
def get_case_data_2() -> CaseData:
    bb1 = stk.BuildingBlock('[C+2][N+]Br', [stk.BromoFactory()])
    canonical_bb1 = bb1.with_canonical_atom_ordering()
    bb2 = stk.BuildingBlock('IS[O+]', [stk.IodoFactory()])
    canonical_bb2 = bb2.with_canonical_atom_ordering()

    return CaseData(
        molecule=stk.ConstructedMolecule(
            topology_graph=stk.polymer.Linear(
                building_blocks=(bb1, bb2),
                repeating_unit='AB',
                num_repeating_units=1,
            ),
        ),
        result=stk.ConstructedMolecule.init(
            atoms=(
                stk.C(0, 2),
                stk.O(1, 1),
                stk.N(2, 1),
                stk.S(3),
            ),
            bonds=(
                stk.Bond(stk.C(0, 2), stk.N(2, 1), 1),
                stk.Bond(stk.O(1, 1), stk.S(3), 1),
                stk.Bond(stk.N(2, 1), stk.S(3), 1),
            ),
            position_matrix=np.array([]),
            atom_infos=(
                stk.AtomInfo(
                    atom=stk.C(0, 2),
                    building_block_atom=stk.C(0, 2),
                    building_block=canonical_bb1,
                    building_block_id=0,
                ),
                stk.AtomInfo(
                    atom=stk.O(1, 1),
                    building_block_atom=stk.O(0, 1),
                    building_block=canonical_bb2,
                    building_block_id=1,
                ),
                stk.AtomInfo(
                    atom=stk.N(2, 1),
                    building_block_atom=stk.N(2, 1),
                    building_block=canonical_bb1,
                    building_block_id=0,
                ),
                stk.AtomInfo(
                    atom=stk.S(3),
                    building_block_atom=stk.S(2),
                    building_block=canonical_bb2,
                    building_block_id=1,
                ),
            ),
            bond_infos=(
                stk.BondInfo(
                    bond=stk.Bond(stk.C(0, 2), stk.N(2, 1), 1),
                    building_block=canonical_bb1,
                    building_block_id=0,
                ),
                stk.BondInfo(
                    bond=stk.Bond(stk.O(1, 1), stk.S(3), 1),
                    building_block=canonical_bb2,
                    building_block_id=1,
                ),
                stk.BondInfo(
                    bond=stk.Bond(stk.N(2, 1), stk.S(3), 1),
                    building_block=None,
                    building_block_id=None,
                ),
            ),
            num_building_blocks={
                canonical_bb1: 1,
                canonical_bb2: 1,
            },
        ),
    )