Skip to content

Commit

Permalink
fixup! Make Arkane PEP8 compliant
Browse files Browse the repository at this point in the history
  • Loading branch information
alongd committed Sep 18, 2019
1 parent d71844d commit 7adf2af
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 37 deletions.
21 changes: 9 additions & 12 deletions arkane/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
from arkane.thermo import ThermoJob


species_dict, transition_state_dict, reaction_dict, networkDict = dict(), dict(), dict(), dict()
species_dict, transition_state_dict, reaction_dict, network_dict = dict(), dict(), dict(), dict()
job_list = list()


Expand Down Expand Up @@ -339,7 +339,7 @@ def reaction(label, reactants, products, transitionState=None, kinetics=None, tu

def network(label, isomers=None, reactants=None, products=None, pathReactions=None, bathGas=None):
"""Load a network from an input file"""
global networkDict, species_dict, reaction_dict
global network_dict, species_dict, reaction_dict
logging.info('Loading network {0}...'.format(label))
isomers0 = isomers or []
isomers = []
Expand Down Expand Up @@ -423,7 +423,7 @@ def network(label, isomers=None, reactants=None, products=None, pathReactions=No
path_reactions=path_reactions,
bath_gas=bath_gas,
)
networkDict[label] = network
network_dict[label] = network


def kinetics(label, Tmin=None, Tmax=None, Tlist=None, Tcount=0, sensitivity_conditions=None):
Expand Down Expand Up @@ -466,14 +466,14 @@ def pressureDependence(label, Tmin=None, Tmax=None, Tcount=0, Tlist=None, Pmin=N
maximumGrainSize=None, minimumGrainCount=0, method=None, interpolationModel=None,
activeKRotor=True, activeJRotor=True, rmgmode=False, sensitivity_conditions=None):
"""Generate a pressure dependent job"""
global job_list, networkDict
global job_list, network_dict

if isinstance(interpolationModel, str):
interpolationModel = (interpolationModel,)

nwk = None
if label in list(networkDict.keys()):
nwk = networkDict[label]
if label in list(network_dict.keys()):
nwk = network_dict[label]

job = PressureDependenceJob(network=nwk, Tmin=Tmin, Tmax=Tmax, Tcount=Tcount, Tlist=Tlist,
Pmin=Pmin, Pmax=Pmax, Pcount=Pcount, Plist=Plist,
Expand Down Expand Up @@ -548,13 +548,10 @@ def load_input_file(path):
Load the Arkane input file located at `path` on disk, and return a list of
the jobs defined in that file.
"""
global species_dict, transition_state_dict, reaction_dict, networkDict, job_list
global species_dict, transition_state_dict, reaction_dict, network_dict, job_list

# Clear module-level variables
species_dict = {}
transition_state_dict = {}
reaction_dict = {}
networkDict = {}
species_dict, transition_state_dict, reaction_dict, network_dict = dict(), dict(), dict(), dict()
job_list = []

global_context = {'__builtins__': None}
Expand Down Expand Up @@ -649,7 +646,7 @@ def load_input_file(path):
if atom_energies is not None:
job.arkane_species.atom_energies = atom_energies

return job_list, reaction_dict, species_dict, transition_state_dict, networkDict
return job_list, reaction_dict, species_dict, transition_state_dict, network_dict


def process_model_chemistry(model_chemistry):
Expand Down
40 changes: 20 additions & 20 deletions arkane/kinetics.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ def clear(self):
self.surface = None
self.cr = None

def __get_energy_range(self):
def _get_energy_range(self):
"""
Return the minimum and maximum energy in J/mol on the potential energy surface.
"""
Expand All @@ -434,7 +434,7 @@ def __get_energy_range(self):
self.reaction.transition_state.conformer.E0.value_si / 1000.))
return e0_min, e0_max

def __use_structure_for_label(self, configuration):
def _use_structure_for_label(self, configuration):
"""
Return ``True`` if the configuration should use molecular structures
for its labels or ``False`` otherwise.
Expand All @@ -452,7 +452,7 @@ def __use_structure_for_label(self, configuration):

return use_structures

def __get_text_size(self, text, padding=2, file_format='pdf'):
def _get_text_size(self, text, padding=2, file_format='pdf'):
try:
import cairocffi as cairo
except ImportError:
Expand All @@ -467,7 +467,7 @@ def __get_text_size(self, text, padding=2, file_format='pdf'):
height = extents[3] + 2 * padding
return [0, 0, width, height]

def __draw_text(self, text, cr, x0, y0, padding=2):
def _draw_text(self, text, cr, x0, y0, padding=2):
cr.save()
cr.set_font_size(self.options['fontSizeNormal'])
extents = cr.text_extents(text)
Expand All @@ -479,19 +479,19 @@ def __draw_text(self, text, cr, x0, y0, padding=2):
height = extents[3] + 2 * padding
return [0, 0, width, height]

def __get_label_size(self, configuration, file_format='pdf'):
def _get_label_size(self, configuration, file_format='pdf'):
width = 0
height = 0
bounding_rects = []
if self.__use_structure_for_label(configuration):
if self._use_structure_for_label(configuration):
for spec in configuration.species_list:
rect = MoleculeDrawer().draw(spec.molecule[0], file_format=file_format)[2]
bounding_rects.append(list(rect))
else:
for spec in configuration.species_list:
bounding_rects.append(self.__get_text_size(spec.label, file_format=file_format))
bounding_rects.append(self._get_text_size(spec.label, file_format=file_format))

plus_rect = self.__get_text_size('+', file_format=file_format)
plus_rect = self._get_text_size('+', file_format=file_format)

for rect in bounding_rects:
if width < rect[2]:
Expand All @@ -501,18 +501,18 @@ def __get_label_size(self, configuration, file_format='pdf'):

return [0, 0, width, height]

def __draw_label(self, configuration, cr, x0, y0, file_format='pdf'):
def _draw_label(self, configuration, cr, x0, y0, file_format='pdf'):

bounding_rect = self.__get_label_size(configuration, file_format=file_format)
bounding_rect = self._get_label_size(configuration, file_format=file_format)
padding = 2

use_structures = self.__use_structure_for_label(configuration)
use_structures = self._use_structure_for_label(configuration)
y = y0
for i, spec in enumerate(configuration.species_list):
if i > 0:
rect = self.__get_text_size('+', padding=padding, file_format=file_format)
rect = self._get_text_size('+', padding=padding, file_format=file_format)
x = x0 - 0.5 * (rect[2] - bounding_rect[2]) + 2 * padding
self.__draw_text('+', cr, x, y)
self._draw_text('+', cr, x, y)
y += rect[3]

if use_structures:
Expand All @@ -526,9 +526,9 @@ def __draw_label(self, configuration, cr, x0, y0, file_format='pdf'):
cr.restore()
y += rect[3]
else:
rect = self.__get_text_size(spec.label, padding=padding, file_format=file_format)
rect = self._get_text_size(spec.label, padding=padding, file_format=file_format)
x = x0 - 0.5 * (rect[2] - bounding_rect[2]) + 2 * padding
self.__draw_text(spec.label, cr, x, y)
self._draw_text(spec.label, cr, x, y)
y += rect[3]

return bounding_rect
Expand All @@ -554,10 +554,10 @@ def draw(self, reaction, file_format, path=None):
# Generate the bounding rectangles for each configuration label
label_rects = []
for well in self.wells:
label_rects.append(self.__get_label_size(well, file_format=file_format))
label_rects.append(self._get_label_size(well, file_format=file_format))

# Get energy range (use kJ/mol internally)
e0_min, e0_max = self.__get_energy_range()
e0_min, e0_max = self._get_energy_range()
e0_min *= 0.001
e0_max *= 0.001

Expand All @@ -579,7 +579,7 @@ def draw(self, reaction, file_format, path=None):
raise InputError('Invalid value "{0}" for Eunits parameter.'.format(e_units))

# Determine height required for drawing
e_height = self.__get_text_size('0.0', file_format=file_format)[3] + 6
e_height = self._get_text_size('0.0', file_format=file_format)[3] + 6
y_e0 = (e0_max - 0.0) * e_slope + padding + e_height
height = (e0_max - e0_min) * e_slope + 2 * padding + e_height + 6
for i in range(len(self.wells)):
Expand Down Expand Up @@ -684,7 +684,7 @@ def draw(self, reaction, file_format, path=None):
# Fill the background with white
cr.set_source_rgba(1.0, 1.0, 1.0, 1.0)
cr.paint()
self.__draw_text('E0 ({0})'.format(e_units), cr, 15, 10, padding=2) # write units
self._draw_text('E0 ({0})'.format(e_units), cr, 15, 10, padding=2) # write units

# Draw reactions
e0_reac = self.wells[0].E0 * 0.001 - e0_offset
Expand Down Expand Up @@ -771,7 +771,7 @@ def draw(self, reaction, file_format, path=None):
cr.rectangle(x, y, label_rects[i][2], label_rects[i][3])
cr.set_source_rgba(1.0, 1.0, 1.0, 0.75)
cr.fill()
self.__draw_label(well, cr, x, y, file_format=file_format)
self._draw_label(well, cr, x, y, file_format=file_format)

# Finish Cairo drawing
if file_format == 'png':
Expand Down
2 changes: 1 addition & 1 deletion arkane/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def load_input_file(self, input_file):
loaded set of jobs as a list.
"""
self.input_file = input_file
self.job_list, self.reaction_dict, self.species_dict, self.transition_state_dict, self.networkDict = \
self.job_list, self.reaction_dict, self.species_dict, self.transition_state_dict, self.network_dict = \
load_input_file(self.input_file)
logging.info('')
return self.job_list
Expand Down
8 changes: 4 additions & 4 deletions examples/arkane/explorer/methoxy/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,9 @@
minimumGrainCount = 500,
method = 'modified strong collision',
#Other methods include: 'reservoir state', 'chemically-significant eigenvalues',
interpolationModel = ('pdeparrhenius'),
interpolationModel = 'pdeparrhenius',
activeKRotor = True,
# active_j_rotor = False, # causes Arkane to crash
# active_J_rotor = False, # causes Arkane to crash
rmgmode = False,
)

Expand All @@ -209,6 +209,6 @@
explore_tol=0.01,
energy_tol=8e1,
flux_tol=1e-6,
bathGas={'He':1.0},
maximumRadicalElectrons=2,
bathGas={'He':1.0},
maximumRadicalElectrons=2,
)

0 comments on commit 7adf2af

Please sign in to comment.