Example #1
0
def iteration(A, B, lasso_param):
	Natom = len(A)
	SCF_A = chg_resp.copy_matrixA(A)
	Q_new = np.linalg.solve(A, B)
	SCF_iteration = 100000
	SCF_threshold = 1e-6
	zero_threshold = 1e-200
	
	for Nscf in range(SCF_iteration):
		Q_old = Q_new

		for j in range(Natom-1):

			if abs(Q_old[j]) < zero_threshold:
				Q_old[j] = 0.0

		for j in range(Natom-1):
			if abs(Q_old[j]) >= zero_threshold:
				param = lasso_param / abs(Q_old[j])

			else:
				param = 0

			SCF_A[j][j] = A[j][j] + param

		Q_new = np.linalg.solve(SCF_A, B)

		error = chg_resp.SCF_error(Q_new, Q_old)
		if error < SCF_threshold:
			print "convergence &",Nscf
			break

	#	Q_new = chg_resp.SimpleMixing(Q_new, Q_old, 0.85)
	return Q_new
Example #2
0
def iteration(A, B, lasso_param):
    Natom = len(A)
    SCF_A = chg_resp.copy_matrixA(A)
    Q_new = np.linalg.solve(A, B)
    SCF_iteration = 100000
    SCF_threshold = 1e-6
    zero_threshold = 1e-200

    for Nscf in range(SCF_iteration):
        Q_old = Q_new

        for j in range(Natom - 1):

            if abs(Q_old[j]) < zero_threshold:
                Q_old[j] = 0.0

        for j in range(Natom - 1):
            if abs(Q_old[j]) >= zero_threshold:
                param = lasso_param / abs(Q_old[j])

            else:
                param = 0

            SCF_A[j][j] = A[j][j] + param

        Q_new = np.linalg.solve(SCF_A, B)

        error = chg_resp.SCF_error(Q_new, Q_old)
        if error < SCF_threshold:
            print "convergence &", Nscf
            break

    #	Q_new = chg_resp.SimpleMixing(Q_new, Q_old, 0.85)
    return Q_new
Example #3
0
def main():
	# parse args
	parser = argparse.ArgumentParser(description="calculate the Ridge Charge")
	parser.add_argument("FILE",
						nargs=1,
						help="input file(.mpac)")
	parser.add_argument("-o", "--output",
						nargs=1,
						dest="charge_path",
						help="charge file")
	args = parser.parse_args()

	# setting
	db_path = args.FILE[0]
	fr = open(db_path, "rb")
	data = msgpack.unpackb(fr.read())
	
	Atom_List = data["atoms"]
	Grid_List = data["grids"]
	ESP_List = data["ESP"]
	Mulliken_List = data["mulliken"]
	X = np.array(data["matrixX"])
	Y = np.array(data["matrixY"])
	net_charge = data["net_charge"]
	
	Natom = len(Atom_List)
	Ngrid = len(Grid_List)

	# matrix
	A = mkmat.matrixA(X, Y)
	B = mkmat.matrixB(X, Y, net_charge)
	I = np.matrix(np.identity(Natom))

	# Ridge CHARGE
	Q_new = np.zeros(Natom+1)
	Ridge_A = chg_resp.copy_matrixA(A)
	wt = 1e-1

	chg_resp.Ridge_convert_matrix(Atom_List, A, Ridge_A, wt)
	Ridge_CHARGE = np.linalg.solve(Ridge_A, B)

	# RRMS
	MSE = chg_resp.MSE(X, Y, Ridge_CHARGE)
	ESP_square_sum = chg_resp.ESP_square_sum(Y)
	RRMS = np.sqrt(MSE/ESP_square_sum)

	# write the data
	fw_path = args.charge_path[0]
	fw = open(fw_path, "wb")

	data["Ridge"] = Ridge_CHARGE[:-1]
	packed = msgpack.packb(data)
	fw.write(packed)
	fw.close()
Example #4
0
def main():
    # parse args
    parser = argparse.ArgumentParser(description="calculate the Ridge Charge")
    parser.add_argument("FILE", nargs=1, help="input file(.mpac)")
    parser.add_argument("-o",
                        "--output",
                        nargs=1,
                        dest="charge_path",
                        help="charge file")
    args = parser.parse_args()

    # setting
    db_path = args.FILE[0]
    fr = open(db_path, "rb")
    data = msgpack.unpackb(fr.read())

    Atom_List = data["atoms"]
    Grid_List = data["grids"]
    ESP_List = data["ESP"]
    Mulliken_List = data["mulliken"]
    X = np.array(data["matrixX"])
    Y = np.array(data["matrixY"])
    net_charge = data["net_charge"]

    Natom = len(Atom_List)
    Ngrid = len(Grid_List)

    # matrix
    A = mkmat.matrixA(X, Y)
    B = mkmat.matrixB(X, Y, net_charge)
    I = np.matrix(np.identity(Natom))

    # Ridge CHARGE
    Q_new = np.zeros(Natom + 1)
    Ridge_A = chg_resp.copy_matrixA(A)
    wt = 1e-1

    chg_resp.Ridge_convert_matrix(Atom_List, A, Ridge_A, wt)
    Ridge_CHARGE = np.linalg.solve(Ridge_A, B)

    # RRMS
    MSE = chg_resp.MSE(X, Y, Ridge_CHARGE)
    ESP_square_sum = chg_resp.ESP_square_sum(Y)
    RRMS = np.sqrt(MSE / ESP_square_sum)

    # write the data
    fw_path = args.charge_path[0]
    fw = open(fw_path, "wb")

    data["Ridge"] = Ridge_CHARGE[:-1]
    packed = msgpack.packb(data)
    fw.write(packed)
    fw.close()