geometric/internal.py
def augmentGH(self, xyz, G, H):
        """
        Add extra dimensions to the gradient and Hessian corresponding to the constrained degrees of freedom.
        The Hessian becomes:  H  c
                              cT 0
        where the elements of cT are the first derivatives of the constraint function 
        (typically a single primitive minus a constant) with respect to the DLCs. 
        
        Since we picked a DLC to represent the constraint (cProj), we only set one element 
        in each row of cT to be nonzero. Because cProj = a_i * Prim_i + a_j * Prim_j, we have
        d(Prim_c)/d(cProj) = 1.0/a_c where "c" is the index of the primitive being constrained.
        
        The extended elements of the Gradient are equal to the constraint violation.
        
        Parameters
        ----------
        xyz : np.ndarray
            Flat array containing Cartesian coordinates in atomic units
        G : np.ndarray
            Flat array containing internal coordinate gradient
        H : np.ndarray
            Square array containing internal coordinate Hessian

        Returns
        -------
        GC : np.ndarray
            Flat array containing gradient extended by constraint violations
        HC : np.ndarray
            Square matrix extended by partial derivatives d(Prim)/d(cProj)
        """
        # Number of internals (elements of G)
        ni = len(G)
        # Number of constraints
        nc = len(self.Prims.cPrims)
        # Total dimension
        nt = ni+nc
        # Lower block of the augmented Hessian
        cT = np.zeros((nc, ni), dtype=float)
        # The further change needed in constrained variables:
        # (Constraint values) - (Current values of constraint ICs)
        c0 = -1.0 * self.calcConstraintDiff(xyz)
        for ic, c in enumerate(self.Prims.cPrims):
            # Look up the index of the primitive that is being constrained
            iPrim = self.Prims.Internals.index(c)
            # The DLC corresponding to the constrained primitive (a.k.a. cProj) is self.Vecs[self.cDLC[ic]].
            # For a differential change in the DLC, the primitive that we are constraining changes by:
            cT[ic, self.cDLC[ic]] = 1.0/self.Vecs[iPrim, self.cDLC[ic]]
            # The new constraint algorithm satisfies constraints too quickly and could cause
            # the energy to blow up. Thus, constraint steps are restricted to 0.1 au/radian
            if self.conmethod == 1:
                if c0[ic] < -0.1:
                    c0[ic] = -0.1
                if c0[ic] > 0.1:
                    c0[ic] = 0.1
        # Construct augmented Hessian
        HC = np.zeros((nt, nt), dtype=float)
        HC[0:ni, 0:ni] = H[:,:]
        HC[ni:nt, 0:ni] = cT[:,:]
        HC[0:ni, ni:nt] = cT.T[:,:]
        # Construct augmented gradient
        GC = np.zeros(nt, dtype=float)
        GC[0:ni] = G[:]
        GC[ni:nt] = -c0[:]
        return GC, HC

        Add extra dimensions to the gradient and Hessian corresponding to the constrained degrees of freedom.
        The Hessian becomes:  H  c
                              cT 0
        where the elements of cT are the first derivatives of the constraint function 
        (typically a single primitive minus a constant) with respect to the DLCs. 
        
        Since we picked a DLC to represent the constraint (cProj), we only set one element 
        in each row of cT to be nonzero. Because cProj = a_i * Prim_i + a_j * Prim_j, we have
        d(Prim_c)/d(cProj) = 1.0/a_c where "c" is the index of the primitive being constrained.
        
        The extended elements of the Gradient are equal to the constraint violation.
        
        Parameters
        ----------
        xyz : np.ndarray
            Flat array containing Cartesian coordinates in atomic units
        G : np.ndarray
            Flat array containing internal coordinate gradient
        H : np.ndarray
            Square array containing internal coordinate Hessian

        Returns
        -------
        GC : np.ndarray
            Flat array containing gradient extended by constraint violations
        HC : np.ndarray
            Square matrix extended by partial derivatives d(Prim)/d(cProj)
        
Add extra dimensions to the gradient and Hessian corresponding to the constrained degrees of freedom.
The Hessian becomes:  H  c
cT 0
where the elements of cT are the first derivatives of the constraint function
(typically a single primitive minus a constant) with respect to the DLCs.

Since we picked a DLC to represent the constraint (cProj), we only set one element
in each row of cT to be nonzero. Because cProj = a_i * Prim_i + a_j * Prim_j, we have
d(Prim_c)/d(cProj) = 1.0/a_c where "c" is the index of the primitive being constrained.

The extended elements of the Gradient are equal to the constraint violation.

Parameters

xyz : np.ndarray
Flat array containing Cartesian coordinates in atomic units
G : np.ndarray
Flat array containing internal coordinate gradient
H : np.ndarray
Square array containing internal coordinate Hessian

Returns

GC : np.ndarray
Flat array containing gradient extended by constraint violations
HC : np.ndarray
Square matrix extended by partial derivatives d(Prim)/d(cProj)
Add extra dimensions to the gradient and Hessian corresponding to the constrained degrees of freedom . The Hessian becomes : H c cT 0 where the elements of cT are the first derivatives of the constraint function ( typically a single primitive minus a constant ) with respect to the DLCs . Since we picked a DLC to represent the constraint ( cProj ) we only set one element in each row of cT to be nonzero . Because cProj = a_i * Prim_i + a_j * Prim_j we have d ( Prim_c ) / d ( cProj ) = 1 . 0 / a_c where " c " is the index of the primitive being constrained . The extended elements of the Gradient are equal to the constraint violation . Parameters xyz : np . ndarray Flat array containing Cartesian coordinates in atomic units G : np . ndarray Flat array containing internal coordinate gradient H : np . ndarray Square array containing internal coordinate Hessian Returns GC : np . ndarray Flat array containing gradient extended by constraint violations HC : np . ndarray Square matrix extended by partial derivatives d ( Prim ) / d ( cProj )
def augmentGH(self, xyz, G, H):
        ni = len(G)
        nc = len(self.Prims.cPrims)
        nt = ni+nc
        cT = np.zeros((nc, ni), dtype=float)
        c0 = -1.0 * self.calcConstraintDiff(xyz)
        for ic, c in enumerate(self.Prims.cPrims):
            iPrim = self.Prims.Internals.index(c)
            cT[ic, self.cDLC[ic]] = 1.0/self.Vecs[iPrim, self.cDLC[ic]]
            if self.conmethod == 1:
                if c0[ic] < -0.1:
                    c0[ic] = -0.1
                if c0[ic] > 0.1:
                    c0[ic] = 0.1
        HC = np.zeros((nt, nt), dtype=float)
        HC[0:ni, 0:ni] = H[:,:]
        HC[ni:nt, 0:ni] = cT[:,:]
        HC[0:ni, ni:nt] = cT.T[:,:]
        GC = np.zeros(nt, dtype=float)
        GC[0:ni] = G[:]
        GC[ni:nt] = -c0[:]
        return GC, HC
def augmentGH ( self , xyz , G , H ) : ni = len ( G ) nc = len ( self . Prims . cPrims ) nt = ni + nc cT = np . zeros ( ( nc , ni ) , dtype = float ) c0 = - 1.0 * self . calcConstraintDiff ( xyz ) for ic , c in enumerate ( self . Prims . cPrims ) : iPrim = self . Prims . Internals . index ( c ) cT [ ic , self . cDLC [ ic ] ] = 1.0 / self . Vecs [ iPrim , self . cDLC [ ic ] ] if self . conmethod == 1 : if c0 [ ic ] < - 0.1 : c0 [ ic ] = - 0.1 if c0 [ ic ] > 0.1 : c0 [ ic ] = 0.1 HC = np . zeros ( ( nt , nt ) , dtype = float ) HC [ 0 : ni , 0 : ni ] = H [ : , : ] HC [ ni : nt , 0 : ni ] = cT [ : , : ] HC [ 0 : ni , ni : nt ] = cT . T [ : , : ] GC = np . zeros ( nt , dtype = float ) GC [ 0 : ni ] = G [ : ] GC [ ni : nt ] = - c0 [ : ] return GC , HC
Add extra dimensions to the gradient and Hessian corresponding to the constrained degrees of freedom.
Add extra dimensions to the gradient and Hessian corresponding to the constrained degrees of freedom .
"""
        Add extra dimensions to the gradient and Hessian corresponding to the constrained degrees of freedom.
        The Hessian becomes:  H  c
                              cT 0
        where the elements of cT are the first derivatives of the constraint function 
        (typically a single primitive minus a constant) with respect to the DLCs. 
        
        Since we picked a DLC to represent the constraint (cProj), we only set one element 
        in each row of cT to be nonzero. Because cProj = a_i * Prim_i + a_j * Prim_j, we have
        d(Prim_c)/d(cProj) = 1.0/a_c where "c" is the index of the primitive being constrained.
        
        The extended elements of the Gradient are equal to the constraint violation.
        
        Parameters
        ----------
        xyz : np.ndarray
            Flat array containing Cartesian coordinates in atomic units
        G : np.ndarray
            Flat array containing internal coordinate gradient
        H : np.ndarray
            Square array containing internal coordinate Hessian

        Returns
        -------
        GC : np.ndarray
            Flat array containing gradient extended by constraint violations
        HC : np.ndarray
            Square matrix extended by partial derivatives d(Prim)/d(cProj)
        """ # Number of internals (elements of G) # Number of constraints # Total dimension # Lower block of the augmented Hessian # The further change needed in constrained variables: # (Constraint values) - (Current values of constraint ICs) # Look up the index of the primitive that is being constrained # The DLC corresponding to the constrained primitive (a.k.a. cProj) is self.Vecs[self.cDLC[ic]]. # For a differential change in the DLC, the primitive that we are constraining changes by: # The new constraint algorithm satisfies constraints too quickly and could cause # the energy to blow up. Thus, constraint steps are restricted to 0.1 au/radian # Construct augmented Hessian # Construct augmented gradient
self
xyz
G
H