Exemple #1
0
    def optimize(self, state):
        mch_mol = mch.Molecule(
            atoms=(mch.Atom(
                id=atom.get_id(),
                element_string=atom.__class__.__name__,
            ) for atom in state.get_atoms()),
            bonds=get_mch_bonds(state),
            position_matrix=state.get_position_matrix(),
        )

        mch_mol, result = self._optimizer.get_result(
            mol=mch_mol,
            bond_pair_ids=tuple(get_long_bond_ids(state)),
            subunits=get_subunits(state),
        )

        old_pos_mat = state.get_position_matrix()
        new_pos_mat = mch_mol.get_position_matrix()
        old_extents = (abs(max(old_pos_mat[:, i]) - min(old_pos_mat[:, i]))
                       for i in range(3))
        new_extents = (abs(max(new_pos_mat[:, i]) - min(new_pos_mat[:, i]))
                       for i in range(3))
        ratios = (n / o for n, o in zip(new_extents, old_extents))
        old_lattice = state.get_lattice_constants()
        new_lattice = tuple(old_lattice[i] * ratio
                            for i, ratio in enumerate(ratios))
        state = state.with_lattice_constants(new_lattice)
        return state.with_position_matrix(
            position_matrix=mch_mol.get_position_matrix())
Exemple #2
0
    def optimize(self, state):
        # Define MCHammer molecule to optimize.
        mch_mol = mch.Molecule(
            atoms=(mch.Atom(
                id=atom.get_id(),
                element_string=atom.__class__.__name__,
            ) for atom in state.get_atoms()),
            bonds=tuple(get_mch_bonds(state)),
            position_matrix=state.get_position_matrix(),
        )

        # Run optimization.
        mch_mol, results = self._optimizer.get_result(
            mol=mch_mol,
            bond_pair_ids=tuple(get_long_bond_ids(state)),
            subunits=get_subunits(state),
        )
        return state.with_position_matrix(
            position_matrix=mch_mol.get_position_matrix(), )
Exemple #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)),
    subunits=subunits,
Exemple #4
0
            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,
            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(
Exemple #5
0
def molecule(atoms, bonds, position_matrix):
    return mch.Molecule(
        atoms=atoms,
        bonds=bonds,
        position_matrix=position_matrix
    )
Exemple #6
0
def coll_molecule(coll_atoms, coll_bonds, coll_position_matrix):
    return mch.Molecule(
        atoms=coll_atoms,
        bonds=coll_bonds,
        position_matrix=coll_position_matrix
    )