def test_dihedral_two_atom_selection(four_particle_45_twist):
    mol = four_particle_45_twist
    np.testing.assert_almost_equal(mdt.dihedral(*mol.atoms[1:3]).value_in(u.degrees),
                                   45.0,
                                   decimal=8)

    with pytest.raises(ValueError):  # raises exception because it's not part of a dihedral
        mdt.dihedral(mol.atoms[0], mol.atoms[1])
Beispiel #2
0
def test_dihedral_two_atom_selection(four_particle_45_twist):
    mol = four_particle_45_twist
    np.testing.assert_almost_equal(mdt.dihedral(*mol.atoms[1:3]).value_in(
        u.degrees),
                                   45.0,
                                   decimal=8)

    with pytest.raises(
            ValueError
    ):  # raises exception because it's not part of a dihedral
        mdt.dihedral(mol.atoms[0], mol.atoms[1])
Beispiel #3
0
def test_dihedral_sign_convention(four_particle_45_twist):
    mol = four_particle_45_twist
    mol.atoms[-1].y += 0.4 * u.nm
    np.testing.assert_almost_equal(mdt.dihedral(*mol.atoms).value_in(
        u.degrees),
                                   315.0,
                                   decimal=8)
Beispiel #4
0
def test_set_dihedral(four_particle_45_twist):
    mol = four_particle_45_twist
    mdt.set_dihedral(mol.atoms[0], mol.atoms[1], mol.atoms[2], mol.atoms[3],
                     10.0 * u.degrees)
    np.testing.assert_almost_equal(mdt.dihedral(*mol.atoms).value_in(
        u.degrees),
                                   10.0,
                                   decimal=8)
Beispiel #5
0
def test_set_dihedral_bond_no_adjust(four_particle_45_twist):
    mol = four_particle_45_twist
    bond = mdt.Bond(mol.atoms[1], mol.atoms[2])
    mdt.set_dihedral(bond, 10.0 * u.degrees, adjustmol=False)
    np.testing.assert_almost_equal(mdt.dihedral(*mol.atoms).value_in(
        u.degrees),
                                   10.0,
                                   decimal=8)
    def _get_tool_state(self, selectedAtomIndices):
        # start with everything disabled
        for tool in self.atom_tools.children + self.bond_tools.children:
            tool.disabled = True

        if len(selectedAtomIndices) <= 0:
            return (ipy.HTML('Please click on a bond or atom'), )

        elif len(selectedAtomIndices) is 1:
            atom = self.get_selected_atom(self.mol.atoms, selectedAtomIndices)
            self.adjust_button.disabled = False

            x, y, z = atom.position.value_in(u.angstrom)
            self.x_slider.value = x
            self.x_slider.disabled = False  # for now

            self.y_slider.value = y
            self.y_slider.disabled = False  # for now

            self.z_slider.value = z
            self.z_slider.disabled = False  # for now

            for tool in self.atom_tools.children:
                tool.disabled = True

            return (self.atom_tools, )

        else:
            bonds = self.viewer.get_selected_bonds()
            bond = self.get_selected_bond(bonds)
            self.adjust_button.disabled = False

            # bond length
            self.length_slider.value = bond.a1.distance(bond.a2).value_in(
                u.angstrom)
            self.length_slider.disabled = False
            self.length_slider.description = '<b>Bond distance</b> <span style="color:{c1}">{a1.name}' \
                                             ' - {a2.name}</span>'.format(
                    a1=bond.a1, a2=bond.a2, c1=self.viewer.HIGHLIGHT_COLOR)

            a1_neighbors = set(
                [a for a in bond.a1.bond_graph if a is not bond.a2])
            maxo = max(a1_neighbors, key=lambda x: x.mass)
            bond_neighbors = self.get_bond_neighbors(bonds, bond)

            # Bond angle
            if bond_neighbors['a2']:
                self.dihedral_slider.enable()
                self.angle_slider.enable()
                self.angle_slider.value = mdt.angle(
                    bond.a1, bond.a2, bond_neighbors['a2']).value_in(u.degrees)
                # self.angle_slider.observe(self.set_angle, 'value')
                self.angle_slider.description = '<b>Bond angle</b> <span style="color:{c1}">{a1.name}' \
                                                ' - {a2.name}</span> ' \
                                                '- <span style="color:{c2}">{a3.name}</span>'.format(
                        a1=bond.a1, a2=bond.a2, a3=bond_neighbors['a2'],
                        c1=self.viewer.HIGHLIGHT_COLOR, c2=self.NBR2HIGHLIGHT)
            else:
                self.dihedral_slider.disable()
                self.angle_slider.disable()
                self.angle_slider.description = 'no angle associated with this bond'
                # self.angle_slider.unobserve(self.set_angle)

            # Dihedral twist
            if bond_neighbors['a2'] and bond_neighbors['a1']:
                self.dihedral_slider.value = mdt.dihedral(
                    bond_neighbors['a1'], bond.a1, bond.a2,
                    bond_neighbors['a2']).value_in(u.degrees)
                # self.dihedral_slider.observe(self.set_dihedral, 'value')
                self.dihedral_slider.description = '<b>Dihedral angle</b> <span style="color:{c0}">{a4.name}</span>' \
                                                   ' - <span style="color:{c1}">{a1.name}' \
                                                   ' - {a2.name}</span> ' \
                                                   '- <span style="color:{c2}">{a3.name}</span>'.format(
                        a4=bond_neighbors['a1'], a1=bond.a1, a2=bond.a2, a3=bond_neighbors['a2'],
                        c0=self.NBR1HIGHLIGHT, c1=self.viewer.HIGHLIGHT_COLOR,
                        c2=self.NBR2HIGHLIGHT)
            else:
                self.dihedral_slider.description = 'not a torsion bond'
                # self.dihedral_slider.unobserve(self.set_dihedral)
                self.dihedral_slider.disabled = True

            return [self.bond_tools]
def test_set_dihedral_sign_convention(four_particle_45_twist):
    mol = four_particle_45_twist
    mdt.set_dihedral(mol.atoms[0], mol.atoms[1], mol.atoms[2], mol.atoms[3], -23.0 * u.degrees)
    np.testing.assert_almost_equal(mdt.dihedral(*mol.atoms).value_in(u.degrees),
                                   337.0,
                                   decimal=8)
def test_dihedral_measure(four_particle_45_twist):
    mol = four_particle_45_twist
    np.testing.assert_almost_equal(mdt.dihedral(*mol.atoms).value_in(u.degrees),
                                   45.0,
                                   decimal=8)
def test_dihedral_sign_convention(four_particle_45_twist):
    mol = four_particle_45_twist
    mol.atoms[-1].y += 0.4 * u.nm
    np.testing.assert_almost_equal(mdt.dihedral(*mol.atoms).value_in(u.degrees),
                                   315.0,
                                   decimal=8)
 def dihedral(self, a1, a2, a3=None, a4=None):
     a1, a2, a3, a4 = list(map(self._get_traj_atom, (a1, a2, a3, a4)))
     return mdt.dihedral(a1, a2, a3, a4)
    def _get_tool_state(self, selectedAtomIndices):
        # start with everything disabled
        for tool in self.atom_tools.children + self.bond_tools.children: tool.disabled = True

        if len(selectedAtomIndices) <= 0:
            return (ipy.HTML('Please click on a bond or atom'),)

        elif len(selectedAtomIndices) is 1:
            atom = self.get_selected_atom(self.mol.atoms, selectedAtomIndices)
            self.adjust_button.disabled = False

            x, y, z = atom.position.value_in(u.angstrom)
            self.x_slider.value = x
            self.x_slider.disabled = False  # for now

            self.y_slider.value = y
            self.y_slider.disabled = False  # for now

            self.z_slider.value = z
            self.z_slider.disabled = False  # for now

            for tool in self.atom_tools.children: tool.disabled = True

            return (self.atom_tools,)

        else:
            bonds = self.viewer.get_selected_bonds()
            bond = self.get_selected_bond(bonds)
            self.adjust_button.disabled = False

            # bond length
            self.length_slider.value = bond.a1.distance(bond.a2).value_in(u.angstrom)
            self.length_slider.disabled = False
            self.length_slider.description = '<b>Bond distance</b> <span style="color:{c1}">{a1.name}' \
                                             ' - {a2.name}</span>'.format(
                    a1=bond.a1, a2=bond.a2, c1=self.viewer.HIGHLIGHT_COLOR)

            a1_neighbors = set([a for a in bond.a1.bond_graph if a is not bond.a2])
            maxo = max(a1_neighbors, key=lambda x: x.mass)
            bond_neighbors = self.get_bond_neighbors(bonds, bond)

            # Bond angle
            if bond_neighbors['a2']:
                self.dihedral_slider.enable()
                self.angle_slider.enable()
                self.angle_slider.value = mdt.angle(bond.a1, bond.a2, bond_neighbors['a2']).value_in(u.degrees)
                # self.angle_slider.observe(self.set_angle, 'value')
                self.angle_slider.description = '<b>Bond angle</b> <span style="color:{c1}">{a1.name}' \
                                                ' - {a2.name}</span> ' \
                                                '- <span style="color:{c2}">{a3.name}</span>'.format(
                        a1=bond.a1, a2=bond.a2, a3=bond_neighbors['a2'],
                        c1=self.viewer.HIGHLIGHT_COLOR, c2=self.NBR2HIGHLIGHT)
            else:
                self.dihedral_slider.disable()
                self.angle_slider.disable()
                self.angle_slider.description = 'no angle associated with this bond'
                # self.angle_slider.unobserve(self.set_angle)

            # Dihedral twist
            if bond_neighbors['a2'] and bond_neighbors['a1']:
                self.dihedral_slider.value = mdt.dihedral(bond_neighbors['a1'], bond.a1, bond.a2, bond_neighbors['a2']).value_in(u.degrees)
                # self.dihedral_slider.observe(self.set_dihedral, 'value')
                self.dihedral_slider.description = '<b>Dihedral angle</b> <span style="color:{c0}">{a4.name}</span>' \
                                                   ' - <span style="color:{c1}">{a1.name}' \
                                                   ' - {a2.name}</span> ' \
                                                   '- <span style="color:{c2}">{a3.name}</span>'.format(
                        a4=bond_neighbors['a1'], a1=bond.a1, a2=bond.a2, a3=bond_neighbors['a2'],
                        c0=self.NBR1HIGHLIGHT, c1=self.viewer.HIGHLIGHT_COLOR,
                        c2=self.NBR2HIGHLIGHT)
            else:
                self.dihedral_slider.description = 'not a torsion bond'
                # self.dihedral_slider.unobserve(self.set_dihedral)
                self.dihedral_slider.disabled = True

            return [self.bond_tools]
Beispiel #12
0
def test_dihedral_measure(four_particle_45_twist):
    mol = four_particle_45_twist
    np.testing.assert_almost_equal(mdt.dihedral(*mol.atoms).value_in(
        u.degrees),
                                   45.0,
                                   decimal=8)