Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

import config 

import os 

import sys 

 

 

def reportToLOG(info): 

with open(config.f_log, 'a') as logfile: 

logfile.write(info + '\n') 

 

 

def requiredParameterError(parameter): 

raise IOError('Required input parameter {0} ' 

'is not defined.'.format(parameter)) 

 

 

def inputVariableError(parameter, complaint, explanation): 

raise IOError('Input parameter {0} is not {1}\n ' 

'{2}'.format(parameter, complaint, explanation)) 

 

 

def reportWarning(info): 

warning = 'warning: {0}'.format(info) 

reportToLOG(warning) 

 

def redirectOutput(mode, outputname): 

if mode == 'start': 

config.stdout = os.dup(sys.stdout.fileno()) 

config.stdout_file = open(outputname, 'w') 

os.dup2(config.stdout_file.fileno(), sys.stdout.fileno()) 

elif mode == 'stop': 

if not config.stdout: 

raise Exception('Output redirection has not been started, ' 

'thus it can not be ended.') 

sys.stdout.flush() 

os.dup2(config.stdout, sys.stdout.fileno()) 

config.stdout_file.close() 

 

def redirectErr(mode, outputname): 

if mode == 'start': 

config.stderr = os.dup(sys.stderr.fileno()) 

config.stderr_file = open(outputname, 'w') 

os.dup2(config.stderr_file.fileno(), sys.stderr.fileno()) 

elif mode == 'stop': 

if not config.stderr: 

raise Exception('Error redirection has not been started, ' 

'thus it can not be ended.') 

sys.stderr.flush() 

os.dup2(config.stderr, sys.stderr.fileno()) 

config.stderr_file.close() 

 

def checkDelPhiErrors(filename, mode=None, remove=False): 

exceptions = [] 

if mode == 'readFiles': 

exceptions = ['part of system outside the box!', 

'has a net charge of'] 

elif mode == 'runDelPhi': 

exceptions = ['part of system outside the box!'] 

 

exit_trigger = False 

errors = '' 

with open(filename) as f: 

for line in f: 

ignore_error = False 

if 'WARNING' in line or 'Warning' in line: 

for exception in exceptions: 

if exception in line: 

ignore_error = True 

if not ignore_error: 

exit_trigger = True 

errors += line 

if exit_trigger: 

raise Exception('The following errors have been found on {0}: \n{1}'.format(filename, errors)) 

if remove: 

os.remove(filename)