First three terms of equation (8) on p. 203:

        ``c1 + c2*(M - 6) + c3*(M - 6)**2``
323864
def _compute_magnitude_terms(self, rup, coeffs):
        

        adj_mag = rup.mag - self.CONSTS['ref_mag']
        return coeffs['c1'] + coeffs['c2']*adj_mag + coeffs['c3']*adj_mag**2
805651
def _projection(self, a, b, c):
        
        ab = b - a
        ac = c - a
        return a + ((ab*ac).sum() / (ac*ac).sum()) * ac
14046
def _compute_C1_term(C, dists):
    

    c1_dists = np.zeros_like(dists)
    idx = dists < C['Rc11']
    c1_dists[idx] = C['phi_11']
    idx = (dists >= C['Rc11']) & (dists <= C['Rc21'])
    c1_dists[idx] = C['phi_11'] + (C['phi_21'] - C['phi_11']) * \
        ((dists[idx] - C['Rc11']) / (C['Rc21'] - C['Rc11']))
    idx = dists > C['Rc21']
    c1_dists[idx] = C['phi_21']
    return c1_dists
827767
def _compute_term_3(self, C, rrup, mag):
        
        return (C['a3'] *
                np.log10(rrup + C['a4'] * np.power(10, C['a5'] * mag)))
311794
void pass_3(int fi, 
	      double in[],  int in0, int istride,
	      double out[], int out0, int ostride,
	      int sign, int product) {
      int k, k1;

      int factor = 3;
      int m = n / factor;
      int q = n / product;
      int product_1 = product / factor;
      int jump = (factor - 1) * product_1;

      double tau = sign * Math.sqrt(3.0) / 2.0;
      int di = istride * m;
      int dj = ostride * product_1;
      int i = in0, j = out0;
      double x_real, x_imag;
      for (k = 0; k < q; k++) {
	double twids[] = twiddle[fi][k];
	double w1_real =       twids[0];
	double w1_imag = -sign*twids[1];
	double w2_real =       twids[2];
	double w2_imag = -sign*twids[3];

	for (k1 = 0; k1 < product_1; k1++) {
	  double z0_real = in[i];
	  double z0_imag = in[i+1];
	  double z1_real = in[i+di];
	  double z1_imag = in[i+di+1];
	  double z2_real = in[i+2*di];
	  double z2_imag = in[i+2*di+1];
	  i += istride;

	  /* compute x = W(3) z */

	  /* t1 = z1 + z2 */
	  double t1_real = z1_real + z2_real;
	  double t1_imag = z1_imag + z2_imag;
	  
	  /* t2 = z0 - t1/2 */
	  double t2_real = z0_real - t1_real / 2.0;
	  double t2_imag = z0_imag - t1_imag / 2.0;
	  
	  /* t3 = (+/-) sin(pi/3)*(z1 - z2) */
	  double t3_real = tau * (z1_real - z2_real);
	  double t3_imag = tau * (z1_imag - z2_imag);
	  
  	  /* apply twiddle factors */

	  /* out0 = 1 * (z0 + t1) */
	  out[j]   = z0_real + t1_real;
	  out[j+1] = z0_imag + t1_imag;
	  
	  /* out1 = w1 * (t2 + i t3) */
	  x_real = t2_real - t3_imag;
	  x_imag = t2_imag + t3_real;
	  out[j+dj]   = w1_real * x_real - w1_imag * x_imag;
	  out[j+dj+1] = w1_real * x_imag + w1_imag * x_real;
	  
	  /* out2 = w2 * (t2 - i t3) */
	  x_real = t2_real + t3_imag;
	  x_imag = t2_imag - t3_real;
	  out[j+2*dj]   = w2_real * x_real - w2_imag * x_imag;
	  out[j+2*dj+1] = w2_real * x_imag + w2_imag * x_real;
  
	  j += ostride;
	}
	j += (factor-1) * dj;
      }}
1199953
def _get_magnitude_term(self, C, mag):
        
        dmag = mag - 8.0
        return C["c0"] + C["c3"] * dmag + C["c4"] * (dmag ** 2.)
475784
def _compute_magnitude(self, rup, C):
        
        return C['b1'] + (C['b2'] * rup.mag) + (C['b3'] * (rup.mag ** 2))
872709
def _compute_magnitude_term(self, C, rup):
        
        return C['c2'] * (rup.mag - 8.0) + C['c3'] * (rup.mag - 8.0) ** 2
1104974
def _compute_term3(self, C, rrup):
        
        f3 = np.zeros_like(rrup)

        idx_between_70_130 = (rrup > 70) & (rrup <= 130)
        idx_greater_130 = rrup > 130

        f3[idx_between_70_130] = (
            C['c9'] * (np.log(rrup[idx_between_70_130]) - np.log(70))
        )

        f3[idx_greater_130] = (
            C['c9'] * (np.log(rrup[idx_greater_130]) - np.log(70)) +
            C['c10'] * (np.log(rrup[idx_greater_130]) - np.log(130))
        )

        return f3
396630
function ( vectorA, vectorB, vectorC ) {

		var s, a, b, c,
			tmp = THREE.GeometryUtils.__v1;

		tmp.sub( vectorA, vectorB );
		a = tmp.length();

		tmp.sub( vectorA, vectorC );
		b = tmp.length();

		tmp.sub( vectorB, vectorC );
		c = tmp.length();

		s = 0.5 * ( a + b + c );

		return Math.sqrt( s * ( s - a ) * ( s - b ) * ( s - c ) );

	}
1322398
def Bx(self):        
        
        #  0         self.b3  -self.b2
        # -self.b3   0         self.b1
        #  self.b2  -self.b1   0
        
        
        m = np.zeros((len(self.b1), 3, 3))
        m[:, 0, 1] = +self.b3
        m[:, 0, 2] = -self.b2
        m[:, 1, 0] = -self.b3
        m[:, 1, 2] = +self.b1
        m[:, 2, 0] = +self.b2
        m[:, 2, 1] = -self.b1
        return m
1131202
def _compute_term_1(self, C, mag):
        
        return (
            C['a1'] + C['a2'] * mag + C['a3'] *
            np.power(mag, 2) + C['a4'] * np.power(mag, 3)
            + C['a5'] * np.power(mag, 4) + C['a6'] *
            np.power(mag, 5) + C['a7'] * np.power(mag, 6)
        )
1136421
def get_distance_coefficients(self, C, imt):
        
        c3 = self.c3[imt]["c3"] if self.c3 else C["c3"]
        return c3
273466
def _compute_f1(self, C, mag, rrup):
        
        r = np.sqrt(rrup ** 2 + C['c4'] ** 2)

        f1 = (
            C['a1'] +
            C['a12'] * (8.5 - mag) ** C['n'] +
            (C['a3'] + C['a13'] * (mag - C['c1'])) * np.log(r)
        )

        if mag <= C['c1']:
            f1 += C['a2'] * (mag - C['c1'])
        else:
            f1 += C['a4'] * (mag - C['c1'])

        return f1
34046
public void mul(Complex c) {
        double newreal = real * c.real - imag * c.imag;
        double newimag = real * c.imag + imag * c.real;
        real = newreal;
        imag = newimag;
    }
153198
private static int med3(int a, int b, int c, IntComparator comp) {
	int ab = comp.compare(a,b);
	int ac = comp.compare(a,c);
	int bc = comp.compare(b,c);
	return (ab<0 ?
		(bc<0 ? b : ac<0 ? c : a) :
		(bc>0 ? b : ac>0 ? c : a));
}
912680
def makeHis(segID, N, CA, C, O, geo):
    ''''''
    ##R-Group
    CA_CB_length=geo.CA_CB_length
    C_CA_CB_angle=geo.C_CA_CB_angle
    N_C_CA_CB_diangle=geo.N_C_CA_CB_diangle

    CB_CG_length=geo.CB_CG_length
    CA_CB_CG_angle=geo.CA_CB_CG_angle
    N_CA_CB_CG_diangle=geo.N_CA_CB_CG_diangle
    
    CG_ND1_length=geo.CG_ND1_length
    CB_CG_ND1_angle=geo.CB_CG_ND1_angle
    CA_CB_CG_ND1_diangle=geo.CA_CB_CG_ND1_diangle
    
    CG_CD2_length=geo.CG_CD2_length
    CB_CG_CD2_angle=geo.CB_CG_CD2_angle
    CA_CB_CG_CD2_diangle=geo.CA_CB_CG_CD2_diangle
    
    ND1_CE1_length=geo.ND1_CE1_length
    CG_ND1_CE1_angle=geo.CG_ND1_CE1_angle
    CB_CG_ND1_CE1_diangle=geo.CB_CG_ND1_CE1_diangle
    
    CD2_NE2_length=geo.CD2_NE2_length
    CG_CD2_NE2_angle=geo.CG_CD2_NE2_angle
    CB_CG_CD2_NE2_diangle=geo.CB_CG_CD2_NE2_diangle
    
    carbon_b= calculateCoordinates(N, C, CA, CA_CB_length, C_CA_CB_angle, N_C_CA_CB_diangle)
    CB= Atom("CB", carbon_b, 0.0 , 1.0, " "," CB", 0,"C")
    carbon_g= calculateCoordinates(N, CA, CB, CB_CG_length, CA_CB_CG_angle, N_CA_CB_CG_diangle)
    CG= Atom("CG", carbon_g, 0.0, 1.0, " ", " CG", 0, "C")
    nitrogen_d1= calculateCoordinates(CA, CB, CG, CG_ND1_length, CB_CG_ND1_angle, CA_CB_CG_ND1_diangle)
    ND1= Atom("ND1", nitrogen_d1, 0.0, 1.0, " ", " ND1", 0, "N")
    carbon_d2= calculateCoordinates(CA, CB, CG, CG_CD2_length, CB_CG_CD2_angle, CA_CB_CG_CD2_diangle)
    CD2= Atom("CD2", carbon_d2, 0.0, 1.0, " ", " CD2", 0, "C")
    carbon_e1= calculateCoordinates(CB, CG, ND1, ND1_CE1_length, CG_ND1_CE1_angle, CB_CG_ND1_CE1_diangle)
    CE1= Atom("CE1", carbon_e1, 0.0, 1.0, " ", " CE1", 0, "C")
    nitrogen_e2= calculateCoordinates(CB, CG, CD2, CD2_NE2_length, CG_CD2_NE2_angle, CB_CG_CD2_NE2_diangle)
    NE2= Atom("NE2", nitrogen_e2, 0.0, 1.0, " ", " NE2", 0, "N")

    ##Create Residue Data Structure
    res= Residue((' ', segID, ' '), "HIS", '    ')
    res.add(N)
    res.add(CA)
    res.add(C)
    res.add(O)
    res.add(CB)
    res.add(CG)
    res.add(ND1)
    res.add(CD2)
    res.add(CE1)
    res.add(NE2)
    return res