Example #1
0
def bonds():
    return [
        mch.Bond(0, 0, 1),
        mch.Bond(1, 0, 2),
        mch.Bond(2, 0, 3),
        mch.Bond(3, 3, 4),
        mch.Bond(4, 3, 5)
    ]
Example #2
0
def get_mch_bonds(state):
    """
    Yield the bonds of the :mod:`MCHammer` molecule.

    Parameters
    ----------
    state : :class:`.ConstructionState`
        The state of the molecule under construction.

    Yields
    -------
    :class:`MCHammer.Bond`
        A bond in the molecule.

    """

    for i, bond_infos in enumerate(state.get_bond_infos()):
        ba1 = bond_infos.get_bond().get_atom1().get_id()
        ba2 = bond_infos.get_bond().get_atom2().get_id()
        # Must ensure bond atom id ordering is the same here as in
        # line 30. Therefore, sort here.
        ba1, ba2 = sorted((ba1, ba2))
        yield mch.Bond(id=i, atom_ids=(ba1, ba2))
Example #3
0
import mchammer as mch

benzene = stk.BuildingBlock.init_from_file('benzene.mol')
benzene_atoms = [(atom.get_id(), atom.__class__.__name__)
                 for atom in benzene.get_atoms()]
benzene_bonds = []
for i, bond in enumerate(benzene.get_bonds()):
    # Must ensure that bond atom ids are ordered by atom id.
    b_ids = ((bond.get_atom1().get_id(), bond.get_atom2().get_id())
             if bond.get_atom1().get_id() < bond.get_atom2().get_id() else
             (bond.get_atom2().get_id(), bond.get_atom1().get_id()))
    benzene_bonds.append((i, b_ids))

mch_mol = mch.Molecule(
    atoms=(mch.Atom(id=i[0], element_string=i[1]) for i in benzene_atoms),
    bonds=(mch.Bond(id=i[0], atom1_id=i[1][0], atom2_id=i[1][1])
           for i in benzene_bonds),
    position_matrix=benzene.get_position_matrix(),
)

target_bond_length = 1.2
optimizer = mch.Optimizer(
    step_size=0.25,
    target_bond_length=target_bond_length,
    num_steps=100,
)
subunits = mch_mol.get_subunits(bond_pair_ids=((2, 3), (1, 5)), )
# Get all steps.
mch_result = optimizer.get_trajectory(
    mol=mch_mol,
    bond_pair_ids=((2, 3), (1, 5)),
Example #4
0
        },
    ),
)
cage.write('poc.mol')
stk_long_bond_ids = get_long_bond_ids(cage)
mch_mol = mch.Molecule(
    atoms=(
        mch.Atom(
            id=atom.get_id(),
            element_string=atom.__class__.__name__,
        ) for atom in cage.get_atoms()
    ),
    bonds=(
        mch.Bond(
            id=i,
            atom1_id=bond.get_atom1().get_id(),
            atom2_id=bond.get_atom2().get_id()
        ) for i, bond in enumerate(cage.get_bonds())
    ),
    position_matrix=cage.get_position_matrix(),
)
mch_mol_nci = deepcopy(mch_mol)

optimizer = mch.Optimizer(
    step_size=0.25,
    target_bond_length=1.2,
    num_steps=500,
)
subunits = mch_mol.get_subunits(
    bond_pair_ids=stk_long_bond_ids,
)
Example #5
0
def bonds():
    return [
        mch.Bond(0, (0, 1)), mch.Bond(1, (0, 2)), mch.Bond(2, (0, 3)),
        mch.Bond(3, (3, 4)), mch.Bond(4, (3, 5))
    ]
Example #6
0

@pytest.fixture(
    params=(
        (mch.Atom(id=0, element_string='N'), 0, 'N'),
        (mch.Atom(id=65, element_string='P'), 65, 'P'),
        (mch.Atom(id=2, element_string='C'), 2, 'C'),
    )
)
def atom_info(request):
    return request.param


@pytest.fixture(
    params=(
        (mch.Bond(id=0, atom_ids=(0, 1)), 0, 0, 1),
        (mch.Bond(id=65, atom_ids=(2, 3)), 65, 2, 3),
        (mch.Bond(id=2, atom_ids=(3, 4)), 2, 3, 4),
        (mch.Bond(id=3, atom_ids=(0, 9)), 3, 0, 9),
    )
)
def bond_info(request):
    return request.param


@pytest.fixture
def atoms():
    return [
        mch.Atom(0, 'C'), mch.Atom(1, 'C'), mch.Atom(2, 'C'),
        mch.Atom(3, 'C'), mch.Atom(4, 'C'), mch.Atom(5, 'C'),
    ]
Example #7
0
import matplotlib.pyplot as plt
import os
import stk
import mchammer as mch

benzene = stk.BuildingBlock.init_from_file('benzene.mol')
benzene_atoms = [(atom.get_id(), atom.__class__.__name__)
                 for atom in benzene.get_atoms()]
benzene_bonds = []
for i, bond in enumerate(benzene.get_bonds()):
    b_ids = (bond.get_atom1().get_id(), bond.get_atom2().get_id())
    benzene_bonds.append((i, b_ids))

mch_mol = mch.Molecule(
    atoms=(mch.Atom(id=i[0], element_string=i[1]) for i in benzene_atoms),
    bonds=(mch.Bond(id=i[0], atom_ids=i[1]) for i in benzene_bonds),
    position_matrix=benzene.get_position_matrix(),
)

target_bond_length = 1.2
optimizer = mch.Optimizer(
    step_size=0.25,
    target_bond_length=target_bond_length,
    num_steps=100,
)
subunits = mch_mol.get_subunits(bond_pair_ids=((2, 3), (1, 5)), )
# Get all steps.
mch_mol, mch_result = optimizer.get_trajectory(
    mol=mch_mol,
    bond_pair_ids=((2, 3), (1, 5)),
    subunits=subunits,
Example #8
0
import pytest
import numpy as np
import mchammer as mch


@pytest.fixture(params=(
    (mch.Atom(id=0, element_string='N'), 0, 'N'),
    (mch.Atom(id=65, element_string='P'), 65, 'P'),
    (mch.Atom(id=2, element_string='C'), 2, 'C'),
))
def atom_info(request):
    return request.param


@pytest.fixture(params=(
    (mch.Bond(id=0, atom1_id=0, atom2_id=1), 0, 0, 1),
    (mch.Bond(id=65, atom1_id=2, atom2_id=3), 65, 2, 3),
    (mch.Bond(id=2, atom1_id=3, atom2_id=4), 2, 3, 4),
    (mch.Bond(id=3, atom1_id=0, atom2_id=9), 3, 0, 9),
))
def bond_info(request):
    return request.param


@pytest.fixture
def atoms():
    return [
        mch.Atom(0, 'C'),
        mch.Atom(1, 'C'),
        mch.Atom(2, 'C'),
        mch.Atom(3, 'C'),
            bb1: range(2),
            bb2: (2, 3),
            bb3: 4,
            bb4: 5,
            bb5: range(6, 10),
        }, ), )
cage.write('poc.mol')
stk_long_bond_ids = get_long_bond_ids(cage)
mch_mol = mch.Molecule(
    atoms=(mch.Atom(
        id=atom.get_id(),
        element_string=atom.__class__.__name__,
    ) for atom in cage.get_atoms()),
    bonds=(mch.Bond(id=i,
                    atom_ids=(
                        bond.get_atom1().get_id(),
                        bond.get_atom2().get_id(),
                    )) for i, bond in enumerate(cage.get_bonds())),
    position_matrix=cage.get_position_matrix(),
)

optimizer = mch.Collapser(
    step_size=0.05,
    distance_threshold=1.2,
    scale_steps=True,
)
subunits = get_subunits(mol=cage)
# Get all steps.
mch_mol, mch_result = optimizer.get_trajectory(
    mol=mch_mol,
    bond_pair_ids=stk_long_bond_ids,