GithubHelp home page GithubHelp logo

md-club / potential_solver Goto Github PK

View Code? Open in Web Editor NEW

This project forked from singroup/potential_solver

0.0 2.0 0.0 212 KB

A Python module for solving electrostatic potential of a distribution of point charges using periodic boundary conditions.

License: GNU General Public License v3.0

Python 100.00%

potential_solver's Introduction

PyPointChargePotentialSolver

Created maanantai 19 joulukuu 2016

Description

A Python module for solving electrostatic potential of a distribution of point charges using periodic boundary conditions. Represents point charges as Gaussian charge distributions. The values of the Gaussians are gathered to points on a 3D grid and the resulting charge distribution on grid is transformed using FFT to k-space. Poisson equation is solved in k-space for the electrostatic potential and the result is inverse transformed back to real space.

Since the point charges are smeared, the electric potential near the point charges differs from the potential near actual point charges but further away these two potentials converge. gaussian_width parameter defines the smearing width and thus what is actually "near". The smaller the gaussian_width is the more dense grid of points is needed and the heavier the calculation gets.

Requirements

  • Cython
  • NumPy

Cython must be installed in order to compile the computationally heavy part of the solver. See installition instructions on http://docs.cython.org/src/quickstart/install.html in case you need to install it yourself.

In addition, the solver uses NumPy, and the examples use matplotlib for plotting and the 'nacl_example.py' uses ASE (Atomic Simulation Environment) to create the NaCl structure.

Installition

Put the directory with 'electrostatic_potential_solver.py' and 'gaussians_to_grid.pyx' to your PYTHONPATH environment variable, or run the solver in the directory where the files are.

Usage

See the folder 'examples' for Python script examples with possible use cases of the solver and read the instructions below to understand what happens in them.

The solver is a Python class called 'ElectrostaticPotentialSolver'. To initialize the solver object, use command

solver = ElectrostaticPotentialSolver(atom_coordinates, atom_charges, simulation_cell)

where 'atom_coordinates' is a NumPy array of shape (n_atoms, 3) containing the coordinates of the atoms and 'atom_charges' is an array of shape (n_atoms,) containing the charges of the atoms. 'simulation_cell' is an array of shape (3,) containing the length of the simulation cell in each dimension. The solver needs three computational parameters which determine the accuracy of the solution. These parameters are set using commands

solver.set_parameter('k_cutoff', 3.0) solver.set_parameter('gaussian_width', 0.5) solver.set_parameter('gaussian_cutoff', 6.0)

This set of parameter values has been tested to provide accurate results. 'k_cutoff' is the most important parameter, and you can try smaller values to run faster or higher ones to obtain better accuracy. To actually solve the potential, run

solver.solve_potential()

You can obtain the solution on the grid used by the solver by calling

xs, ys, zs, pot_grid = solver.get_data_grid('potential')

In addition to potential, you can get the components of the electric field by substituting 'potential' by 'efield_x', 'efield_y' or 'efield_z'. For convenience, the class provides also a method for obtaining a slice of values at a certain height along one of the axes. It can be used as

xs, ys, pot_slice = solver.get_data_slice('potential', height, normal_direction='z')

where 'height' determines the position along one of the axes at which the slice is taken and 'normal_direction' determines that axis. normal_direction='z' means slice along xy plane, for example.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.