コード例 #1
0
def test_subst_ibond_equals_ipos():
    with pytest.raises(ValueError, match=r'sub and bond indices .*'):
        elem, xyz, vec = substitute.subst(eg.c2h4[0],
                                          eg.c2h4[1],
                                          'f',
                                          2,
                                          ibond=2)
コード例 #2
0
def test_subst_fluoro_vec():
    vec = np.ones_like(eg.c2h4[1])
    elem, xyz, vec = substitute.subst(eg.c2h4[0], eg.c2h4[1], 'f', 2, vec=vec)
    soln = np.copy(vec)
    soln[2] = 0.
    assert np.all(elem == eg.c2h3f[0])
    assert np.allclose(xyz, eg.c2h3f[1])
    assert np.allclose(vec, soln)
コード例 #3
0
def test_subst_pl_equals_ibond():
    with pytest.raises(ValueError, match=r'plane and bond indices .*'):
        elem, xyz, vec = substitute.subst(eg.c2h4[0],
                                          eg.c2h4[1],
                                          'f',
                                          2,
                                          ibond=3,
                                          pl=3)
コード例 #4
0
def test_subst_methyl_plane_vec():
    elem, xyz, vec = substitute.subst(eg.c2h4[0],
                                      eg.c2h4[1],
                                      'ch3',
                                      2,
                                      pl=[1, 1, 1])
    assert np.all(elem == eg.c2h3me_ax[0])
    assert np.allclose(xyz, eg.c2h3me_ax[1])
コード例 #5
0
def test_subst_fluoro_vec():
    vec = np.ones_like(eg.c2h4[1])
    elem, xyz, vec = substitute.subst(eg.c2h4[0], eg.c2h4[1], 'f', 2, vec=vec)
    soln = np.copy(vec)
    soln[2] = 0.
    assert np.all(elem == eg.c2h3f[0])
    assert np.allclose(xyz, eg.c2h3f[1])
    assert np.allclose(vec, soln)
コード例 #6
0
ファイル: molecule.py プロジェクト: ryjmacdonell/gimbal
    def subst(self, lbl, isub, ibond=None, pl=None):
        """Replaces an atom or set of atoms with a substituent.

        Parameters
        ----------
        lbl : str
            The substituent label.
        isub : int or list
            The atomic index (or indices) to be replaced by the substituent.
        ibond : int, optional
            The atomic index of the atom bonded to position isub. If None
            (default), the nearest atom is chosen.
        pl : int or array_like, optional
            The atomic index or vector defining the xz-plane of the
            substituent. See :func:`substitute.subst` for more details.
        """
        args = (self._elem, self._xyz, lbl, isub)
        kwargs = dict(ibond=ibond, pl=pl, vec=self._vec)
        self._elem, self._xyz, vec = substitute.subst(*args, **kwargs)
        if self.print_vec:
            self._vec = vec
        else:
            self._vec = np.zeros_like(self._xyz)
        self._check()
コード例 #7
0
def test_subst_methyl_plane_vec():
    elem, xyz, vec = substitute.subst(eg.c2h4[0], eg.c2h4[1], 'ch3', 2,
                                      pl=[1, 1, 1])
    assert np.all(elem == eg.c2h3me_ax[0])
    assert np.allclose(xyz, eg.c2h3me_ax[1])
コード例 #8
0
def test_subst_fluoro_ibond():
    elem, xyz, vec = substitute.subst(eg.c2h4[0], eg.c2h4[1], 'f', 2, ibond=0)
    assert np.all(elem == eg.c2h3f[0])
    assert np.allclose(xyz, eg.c2h3f[1])
コード例 #9
0
def test_subst_fluoro_with_fluoro():
    inp_xyz = np.copy(eg.c2h3f[1])
    inp_xyz[2] += np.ones(3)
    elem, xyz, vec = substitute.subst(eg.c2h3f[0], inp_xyz, 'f', 2)
    assert np.all(elem == eg.c2h3f[0])
    assert np.allclose(xyz, inp_xyz)
コード例 #10
0
def test_subst_fluoro_multisub():
    elem, xyz, vec = substitute.subst(eg.c2h4[0], eg.c2h4[1], 'f', [2, 3])
    assert np.all(elem == np.hstack((eg.c2h3f[0][:3], eg.c2h3f[0][4:])))
    assert np.allclose(xyz, np.vstack((eg.c2h3f[1][:3], eg.c2h3f[1][4:])))
コード例 #11
0
def test_subst_fluoro_default():
    elem, xyz, vec = substitute.subst(eg.c2h4[0], eg.c2h4[1], 'f', 2)
    assert np.all(elem == eg.c2h3f[0])
    assert np.allclose(xyz, eg.c2h3f[1])
    assert np.allclose(vec, np.zeros_like(xyz))
コード例 #12
0
def test_subst_fluoro_multisub():
    elem, xyz, vec = substitute.subst(eg.c2h4[0], eg.c2h4[1], 'f', [2, 3])
    assert np.all(elem == np.hstack((eg.c2h3f[0][:3], eg.c2h3f[0][4:])))
    assert np.allclose(xyz, np.vstack((eg.c2h3f[1][:3], eg.c2h3f[1][4:])))
コード例 #13
0
ファイル: molecule.py プロジェクト: ryjmacdonell/geomtools
 def subst(self, lbl, isub, ibond=None, pl=None):
     """Replaces an atom or set of atoms with a substituent."""
     args = (self._elem, self._xyz, lbl, isub)
     kwargs = dict(ibond=ibond, pl=pl, vec=self._vec)
     self._elem, self._xyz, self._vec = substitute.subst(*args, **kwargs)
     self._check()
コード例 #14
0
def test_subst_fluoro_ibond():
    elem, xyz, vec = substitute.subst(eg.c2h4[0], eg.c2h4[1], 'f', 2, ibond=0)
    assert np.all(elem == eg.c2h3f[0])
    assert np.allclose(xyz, eg.c2h3f[1])
コード例 #15
0
def test_subst_fluoro_with_fluoro():
    inp_xyz = np.copy(eg.c2h3f[1])
    inp_xyz[2] += np.ones(3)
    elem, xyz, vec = substitute.subst(eg.c2h3f[0], inp_xyz, 'f', 2)
    assert np.all(elem == eg.c2h3f[0])
    assert np.allclose(xyz, inp_xyz)
コード例 #16
0
def test_subst_ibond_equals_ipos():
    with pytest.raises(ValueError, match=r'sub and bond indices .*'):
        elem, xyz, vec = substitute.subst(eg.c2h4[0], eg.c2h4[1], 'f', 2,
                                          ibond=2)
コード例 #17
0
def test_subst_pl_equals_ibond():
    with pytest.raises(ValueError, match=r'plane and bond indices .*'):
        elem, xyz, vec = substitute.subst(eg.c2h4[0], eg.c2h4[1], 'f', 2,
                                          ibond=3, pl=3)
コード例 #18
0
def test_subst_fluoro_default():
    elem, xyz, vec = substitute.subst(eg.c2h4[0], eg.c2h4[1], 'f', 2)
    assert np.all(elem == eg.c2h3f[0])
    assert np.allclose(xyz, eg.c2h3f[1])
    assert vec is None