Beispiel #1
0
    (opts, args) = parser.parse_args()
    if len(args) < 2:
        print(usage)
        exit(-1)

    esp_cube_file = args[0]
    chg_file = args[1]

    # load cube file with electrostatic potential (esp)
    print("load ESP from cube file...")
    atomlist, origin, axes, data = Cube.readCube(esp_cube_file)
    if opts.fit_centers != "":
        print("loading fit centers from '%s'" % opts.fit_centers)
        atomlist = XYZ.read_xyz(opts.fit_centers)[0]
    # extract positions of points and values of ESP
    points, epot = Cube.get_points_and_values(origin, axes, data)

    # fit point charges
    chelpg = CHELPG()
    chelpg.setFitPoints(points, epot)
    chelpg.setAtomicCenters(atomlist, charge=0)
    partial_charges = chelpg.fitESP()

    # save point charges
    if opts.format == 'charges':
        np.savetxt(chg_file, partial_charges)
    else:
        XYZ.write_charges(chg_file, atomlist, partial_charges)
    print("partial charges saved to '%s'" % chg_file)
    dx = la.norm(axes[0])
    dy = la.norm(axes[1])
    dz = la.norm(axes[2])
    # volume element, assuming the axes are orthogonal
    dV = dx * dy * dz
    # find total magnetic dipole moment
    mtot = np.array([np.sum(Mx * dV), np.sum(My * dV), np.sum(Mz * dV)])

    # load cube files for components of vector potential
    print "load magnetic vector potential from cube files..."
    atomlist, origin, axes, Ax_data = Cube.readCube(Ax_cube_file)
    atomlist, origin, axes, Ay_data = Cube.readCube(Ay_cube_file)
    atomlist, origin, axes, Az_data = Cube.readCube(Az_cube_file)
    # extract positions of points and values of A
    points, Ax = Cube.get_points_and_values(origin, axes, Ax_data)
    points, Ay = Cube.get_points_and_values(origin, axes, Ay_data)
    points, Az = Cube.get_points_and_values(origin, axes, Az_data)

    # fit magnetic dipoles
    fitter = MagneticDipoleFitter()
    fitter.setFitPoints(points, Ax, Ay, Az)
    # fitting centers
    if opts.fit_centers != "":
        print "loading fit centers from '%s'" % opts.fit_centers
        atomlist = XYZ.read_xyz(opts.fit_centers)[0]
    fitter.setAtomicCenters(atomlist)

    magnetic_dipoles = fitter.fitVectorPotential(mtot)

    # save magnetic dipoles