Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup cython #3496

Merged
merged 13 commits into from
Feb 17, 2020
5 changes: 4 additions & 1 deletion src/core/particle_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1366,7 +1366,7 @@ void remove_id_from_map(int part_id, int type) {
int get_random_p_id(int type, int random_index_in_type_map) {
if (random_index_in_type_map + 1 > particle_type_map.at(type).size())
throw std::runtime_error("The provided index exceeds the number of "
"particles listed in the type_map");
"particle types listed in the particle_type_map");
return *std::next(particle_type_map[type].begin(), random_index_in_type_map);
}

Expand All @@ -1376,6 +1376,9 @@ void add_id_to_type_map(int part_id, int type) {
}

int number_of_particles_with_type(int type) {
if (particle_type_map.count(type) == 0)
throw std::runtime_error("The provided particle type does not exist in "
"the particle_type_map");
return static_cast<int>(particle_type_map.at(type).size());
}

Expand Down
8 changes: 4 additions & 4 deletions src/python/espressomd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
# Define the espressomd package

# Initialize MPI, start the main loop on the slaves
import espressomd._init
from . import _init

from espressomd.system import System
from espressomd.code_info import features, all_features
from espressomd.cuda_init import gpu_available
from .system import System
from .code_info import features, all_features
from .cuda_init import gpu_available


class FeaturesError(Exception):
Expand Down
2 changes: 1 addition & 1 deletion src/python/espressomd/actors.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
include "myconfig.pxi"
from .highlander import ThereCanOnlyBeOne
from .utils import handle_errors
from .utils cimport handle_errors

cdef class Actor:

Expand Down
5 changes: 1 addition & 4 deletions src/python/espressomd/analyze.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,8 @@
# For C-extern Analysis

cimport numpy as np
from espressomd.utils cimport *
from .utils cimport Vector9d
from libcpp.string cimport string # import std::string as string
from .utils cimport Vector3i, Vector3d, Vector9d, List
from libcpp.vector cimport vector # import std::vector as vector
from libcpp.map cimport map # import std::map as map

cdef extern from "<array>" namespace "std" nogil:
cdef cppclass array4 "std::array<double, 4>":
Expand Down
28 changes: 12 additions & 16 deletions src/python/espressomd/analyze.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,21 @@
# For C-extern Analysis
include "myconfig.pxi"
from . cimport analyze
from . cimport utils
from . cimport particle_data
from . import utils
from . import code_info
from . import particle_data
from libcpp.string cimport string # import std::string as string
from libcpp.vector cimport vector # import std::vector as vector
from libcpp.map cimport map # import std::map as map
from .interactions import *
from espressomd.interactions cimport *
from .interactions cimport BONDED_IA_NONE
from .interactions cimport bonded_ia_params
import numpy as np
cimport numpy as np
from globals cimport n_configs

from .utils import array_locked
from .globals import Globals

from collections import OrderedDict
from .system import System
from espressomd.utils import is_valid_type
from .utils import array_locked, is_valid_type
from .utils cimport Vector3i, Vector3d, Vector9d, List
from .utils cimport handle_errors, check_type_or_throw_except
from .utils cimport create_nparray_from_double_array, \
create_nparray_from_int_list, \
create_int_list_from_python_object


class Analysis:
Expand All @@ -54,7 +50,7 @@ class Analysis:
def append(self):
"""Append configuration for averaged analysis."""
assert analyze.n_part, "No particles to append!"
if analyze.n_configs > 0:
if n_configs > 0:
assert analyze.n_part_conf == analyze.n_part, \
"All configurations stored must have the same length"

Expand Down Expand Up @@ -846,7 +842,7 @@ class Analysis:
n_conf = n_configs

if r_max is None:
r_max = min_box_l / 2.0
r_max = min(Globals().box_l) / 2

cdef vector[double] rdf
rdf.resize(r_bins)
Expand Down Expand Up @@ -921,7 +917,7 @@ class Analysis:
raise ValueError("type_list_b has to be a list!")

if r_max is None:
r_max = min_box_l / 2.0
r_max = min(Globals().box_l) / 2

assert r_min >= 0.0, "r_min was chosen too small!"
assert not log_flag or r_min != 0.0, "r_min cannot include zero"
Expand Down
2 changes: 0 additions & 2 deletions src/python/espressomd/cellsystem.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ from libcpp cimport bool
from libcpp.vector cimport vector
from libcpp.pair cimport pair

from .utils cimport Vector3i

cdef extern from "communication.hpp":
void mpi_bcast_cell_structure(int cs)
int n_nodes
Expand Down
16 changes: 8 additions & 8 deletions src/python/espressomd/cellsystem.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
from grid cimport node_grid
from . cimport cellsystem
from .grid cimport node_grid
from . cimport integrate
from globals cimport *
from .globals cimport FIELD_SKIN, FIELD_NODEGRID, FIELD_MAXNUMCELLS, FIELD_MINNUMCELLS
from .globals cimport max_cut, verlet_reuse, n_layers, dd, cell_structure, \
min_num_cells, max_num_cells, skin
from .globals cimport mpi_bcast_parameter, calc_processor_min_num_cells
import numpy as np
from espressomd.utils cimport handle_errors
from espressomd.utils import is_valid_type
from .utils cimport handle_errors
from .utils import is_valid_type

cdef class CellSystem:
def set_domain_decomposition(self, use_verlet_lists=True,
fully_connected=[False,
False,
False]):
fully_connected=[False, False, False]):
"""
Activates domain decomposition cell system.

Expand Down
2 changes: 1 addition & 1 deletion src/python/espressomd/checkpointing.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import os
import re
import signal
from espressomd.utils import is_valid_type
from .utils import is_valid_type

try:
import cPickle as pickle
Expand Down
3 changes: 2 additions & 1 deletion src/python/espressomd/collision_detection.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from .script_interface import ScriptInterfaceHelper, script_interface_register
from .utils import handle_errors, to_str
from .utils import to_str
from .utils cimport handle_errors
from .interactions import BondedInteraction, BondedInteractions


Expand Down
76 changes: 44 additions & 32 deletions src/python/espressomd/drude_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import espressomd.interactions
from espressomd import has_features
from . import interactions
from .__init__ import has_features

# Dict with Drude type infos
drude_dict = {}
Expand All @@ -35,29 +35,35 @@ def add_drude_particle_to_core(system, harmonic_bond, thermalized_bond,
"""
Adds a Drude particle with specified id, type, and mass to the system.
Checks if different Drude particles have different types.
Collects types/charges/polarizations/Thole factors for intramol. core-Drude short-range exclusion and Thole interaction.
Collects types/charges/polarizations/Thole factors for intramolecular
core-Drude short-range exclusion and Thole interaction.

Attributes
----------

system : Instance of :attr:`espressomd.system.System`
harmonic_bond: This method adds this harmonic bond to between Drude particle and core
thermalized_bond: This method adds this thermalized_bond to between Drude particle and core
p_core: The existing core particle
system : :class:`espressomd.system.System`
harmonic_bond: :class:`espressomd.interactions.HarmonicBond`
Add this harmonic bond to between Drude particle and core
thermalized_bond: :class:`espressomd.interactions.ThermalizedBond`
Add this thermalized_bond to between Drude particle and core
p_core: :class:`espressomd.particle_data.ParticleHandle`
The existing core particle
id_drude: :obj:`int`
This method creates the Drude particle and assigns this id.
This method creates the Drude particle and assigns this id.
type_drude: :obj:`int`
The type of the newly created Drude particle
The type of the newly created Drude particle
alpha : :obj:`float`
The polarizability in units of inverse volume. Related to the charge of the Drude particle.
The polarizability in units of inverse volume. Related to the charge
of the Drude particle.
mass_drude : :obj:`float`
The mass of the newly created Drude particle
The mass of the newly created Drude particle
coulomb_prefactor : :obj:`float`
Required to calculate the charge of the Drude particle.
Required to calculate the charge of the Drude particle.
thole_damping : :obj:`float`
Thole damping factor of the Drude pair. Comes to effect if add_all_thole() method is used.
Thole damping factor of the Drude pair. Comes to effect if
:meth:`add_all_thole()` method is used.
verbose : :obj:`bool`
Turns on verbosity.
Turns on verbosity.

"""

Expand Down Expand Up @@ -132,13 +138,13 @@ def add_thole_pair_damping(system, t1, t2, verbose=False):
Attributes
----------

system : Instance of :attr:`espressomd.system.System`
system : :class:`espressomd.system.System`
t1 : :obj:`int`
Type 1
t2 : :obj:`int`
Type 2
verbose : :obj:`bool`
Turns on verbosity.
Turns on verbosity.

"""

Expand All @@ -155,14 +161,15 @@ def add_thole_pair_damping(system, t1, t2, verbose=False):

def add_all_thole(system, verbose=False):
"""
Calls add_thole_pair_damping() for all necessary combinations to create the interactions.
Calls :meth:`add_thole_pair_damping()` for all necessary combinations to
create the interactions.

Attributes
----------

system : Instance of :attr:`espressomd.system.System`
system : :class:`espressomd.system.System`
verbose : :obj:`bool`
Turns on verbosity.
Turns on verbosity.

"""

Expand Down Expand Up @@ -191,9 +198,9 @@ def setup_and_add_drude_exclusion_bonds(system, verbose=False):
Attributes
----------

system : Instance of :attr:`espressomd.system.System`
system : :class:`espressomd.system.System`
verbose: :obj:`bool`
Turns on verbosity.
Turns on verbosity.

"""

Expand All @@ -203,7 +210,7 @@ def setup_and_add_drude_exclusion_bonds(system, verbose=False):
#...exclusions with core
qd = drude_dict[td]["q"] # Drude charge
qc = drude_dict[td]["qc"] # Core charge
subtr_sr_bond = espressomd.interactions.BondedCoulombSRBond(
subtr_sr_bond = interactions.BondedCoulombSRBond(
q1q2=-qd * qc)
system.bonded_inter.add(subtr_sr_bond)
drude_dict[td]["subtr_sr_bonds_drude-core"] = subtr_sr_bond
Expand Down Expand Up @@ -232,12 +239,15 @@ def setup_intramol_exclusion_bonds(system, mol_drude_types, mol_core_types,
Attributes
----------

system : Instance of :attr:`espressomd.system.System`
mol_drude_types : List of types of Drude particles within the molecule
mol_core_types : List of types of core particles within the molecule
mol_core_partial_charges : List of partial charges of core particles within the molecule
system : :class:`espressomd.system.System`
mol_drude_types :
List of types of Drude particles within the molecule
mol_core_types :
List of types of core particles within the molecule
mol_core_partial_charges :
List of partial charges of core particles within the molecule
verbose : :obj:`bool`
Turns on verbosity.
Turns on verbosity.

"""

Expand All @@ -250,7 +260,7 @@ def setup_intramol_exclusion_bonds(system, mol_drude_types, mol_core_types,
#...excluding the Drude core partner
if drude_dict[td]["core_type"] != tc:
qd = drude_dict[td]["q"] # Drude charge
subtr_sr_bond = espressomd.interactions.BondedCoulombSRBond(
subtr_sr_bond = interactions.BondedCoulombSRBond(
q1q2=-qd * qp)
system.bonded_inter.add(subtr_sr_bond)
drude_dict[td]["subtr_sr_bonds_intramol"][
Expand All @@ -268,11 +278,13 @@ def add_intramol_exclusion_bonds(system, drude_ids, core_ids, verbose=False):
Attributes
----------

system : Instance of :attr:`espressomd.system.System`
drude_ids : IDs of Drude particles within a molecule.
core_ids : IDs of core particles within a molecule.
system : :class:`espressomd.system.System`
drude_ids :
IDs of Drude particles within a molecule.
core_ids :
IDs of core particles within a molecule.
verbose : :obj:`bool`
Turns on verbosity.
Turns on verbosity.

"""

Expand Down
2 changes: 0 additions & 2 deletions src/python/espressomd/electrokinetics.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
include "myconfig.pxi"
from libcpp cimport bool

from .utils cimport Vector3i

IF ELECTROKINETICS and CUDA:
cdef extern from "grid_based_algorithms/electrokinetics.hpp":

Expand Down
4 changes: 2 additions & 2 deletions src/python/espressomd/electrokinetics.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ from . import utils
import os
import tempfile
import shutil
from .utils cimport Vector6d
from .utils import is_valid_type
from .utils cimport Vector3i, Vector6d, handle_errors
import numpy as np
from espressomd.utils import is_valid_type

IF ELECTROKINETICS:
cdef class Electrokinetics(HydrodynamicInteraction):
Expand Down
10 changes: 4 additions & 6 deletions src/python/espressomd/electrostatic_extensions.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,12 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Handling of electrostatics

include "myconfig.pxi"
from espressomd.system cimport *
from espressomd.utils cimport *
from espressomd.electrostatics cimport *
from libcpp cimport vector
from utils cimport Vector3d
from .electrostatics cimport *
from libcpp.vector cimport vector
from libcpp cimport bool
from .utils cimport Vector3d

IF ELECTROSTATICS and P3M:

Expand Down
4 changes: 2 additions & 2 deletions src/python/espressomd/electrostatic_extensions.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@

from . cimport utils
include "myconfig.pxi"
from espressomd cimport actors
from . cimport actors
from . import actors
import numpy as np
from espressomd.utils cimport handle_errors
from .utils cimport handle_errors, check_type_or_throw_except, check_range_or_except

IF ELECTROSTATICS and P3M:
from espressomd.electrostatics import check_neutrality
Expand Down
Loading