Index: utils/Bash/Makefile.am
===================================================================
--- utils/Bash/Makefile.am	(revision d08ab389fd2efbb426bd7cda87ea43a90ce9d3f6)
+++ utils/Bash/Makefile.am	(revision d08ab389fd2efbb426bd7cda87ea43a90ce9d3f6)
@@ -0,0 +1,8 @@
+
+BASH_TOOLS = \
+	Bash/bash_completion
+
+EXTRA_DIST += Bash/bash_completion
+CLEANFILES += ${BASH_TOOLS}
+bin_SCRIPTS += ${BASH_TOOLS}
+
Index: utils/Bash/bash_completion
===================================================================
--- utils/Bash/bash_completion	(revision d08ab389fd2efbb426bd7cda87ea43a90ce9d3f6)
+++ utils/Bash/bash_completion	(revision d08ab389fd2efbb426bd7cda87ea43a90ce9d3f6)
@@ -0,0 +1,78 @@
+# bash_completion for molecuilder 
+#
+# gives a list of all available actions, gives list of options for the last action
+
+function _molecuilder_option()
+{
+	local cmd="${1##*/}"
+	local word=${COMP_WORDS[COMP_CWORD]}
+	local line=${COMP_LINE}
+	option=`echo $line | awk -F"--" {'print $NF'} | tr -d \ `
+	previousoption=`echo $line | awk -F"--" {'print $(NF-1)'} | tr -d \ `
+	#echo "current option is '$word', line is '$line', and cmd is '$cmd', last option is '$option', and last but one is '$previousoption'."
+	COMPREPLY=()
+	# if current option is molecuilder, give all available actions
+	if test x"$option" = x"molecuilder"; then
+		# "molecuilder "
+		COMPREPLY=($($cmd --help | grep "^'.*'" | awk -F":" {'print "--"$1'} | tr -d \'))
+	else
+		# if current argument is void, look at previous (if its not molecuilder)
+		if test x"$option" = x""; then
+			if test x"$previousoption" = x"molecuilder"; then
+				# "molecuilder --"
+				COMPREPLY=($($cmd --help | grep "^'.*'" | awk -F":" {'print "--"$1'} | tr -d \'))
+			else
+				# "molecuilder --some-action --"
+				COMPREPLY=($($cmd --help | grep "^'$previousoption.*'" | awk -F":" {'print "--"$1'} | tr -d \'))
+				if  test ${#COMPREPLY[*]} -eq 0; then
+					# "molecuilder --some-option --"
+					COMPREPLY=($($cmd --help | grep "^'.*'" | awk -F":" {'print "--"$1'} | tr -d \'))
+				else
+					COMPREPLY=($($cmd --help --actionname "$previousoption" | grep Option\  | awk -F"'" {'print "--"$2'} | tr -d \'))
+					# if action has no options, give list of actions
+					if  test ${#COMPREPLY[*]} -eq 0; then
+						COMPREPLY=($($cmd --help | grep "^'.*'" | awk -F":" {'print "--"$1'} | tr -d \'))
+					fi
+				fi
+			fi
+		elif test -z `echo "$word" 2>/dev/null | grep "\-\-"`; then
+			# "molecuilder somefile/value"
+			COMPREPLY=( $( compgen -W "$( ls --color=n -1 ${word}*.in ${word}*.pdb ${word}*.pcp ${word}*.psi ${word}*.data ${word}*.xyz 2>/dev/null| sed -e 's/ /\\ /g' )" -- $cur ))
+		else
+			# "molecuilder --something"
+			COMPREPLY=($($cmd --help | grep "^'$option.*'" | awk -F":" {'print "--"$1'} | tr -d \'))
+			# check whether its an action
+			if test ${#COMPREPLY[*]} -eq 1; then
+				# check whether it's same as option
+				if test x"${COMPREPLY[0]}" = x"--$option"; then
+					# "molecuilder --an-action"
+					#echo "Giving help for option $option"
+					COMPREPLY=($($cmd --help --actionname "$option" | grep Option\  | awk -F"'" {'print "--"$2'} | tr -d \'))
+					# if action has no options, give list of actions
+					if  test ${#COMPREPLY[*]} -eq 0; then
+						COMPREPLY=($($cmd --help | grep "^'.*'" | awk -F":" {'print "--"$1'} | tr -d \'))
+					fi
+				fi
+			fi
+			# if the "action" is unknown, it must be actually an option (segment), give all available options from previous action
+			if test ${#COMPREPLY[*]} -eq 0; then
+				# "molecuilder --an-action --opt.."
+				COMPREPLY=($($cmd --help --actionname "$previousoption" | grep Option\ | grep $option | awk -F"'" {'print "--"$2'} | tr -d \'))
+				# if action has no options, give list of actions
+				if  test ${#COMPREPLY[*]} -eq 0; then
+					COMPREPLY=($($cmd --help | grep "^'.*'" | awk -F":" {'print "--"$1'} | tr -d \'))
+				else
+					#if we have a complete option, give again all available actions
+					if test x"${COMPREPLY[0]}" = x"--$option"; then
+						# "molecuilder --an-action --one-of-its-options"
+						COMPREPLY=($($cmd --help | grep "^'.*'" | awk -F":" {'print "--"$1'} | tr -d \'))
+					fi
+				fi
+			fi
+		fi
+	fi
+	#echo "returning ${COMPREPLY[*]}."
+	return 0
+}
+
+complete -F _molecuilder_option molecuilder
Index: utils/HOWTO-boxmaker
===================================================================
--- utils/HOWTO-boxmaker	(revision c015b3946b9bb714ae6740f4fbfd3378234a0404)
+++ 	(revision )
@@ -1,146 +1,0 @@
-Boxmaker creates boxes of specific density filled with molecules
-
-==========================================================
-
-Usage:
-    boxmaker.py <basename> [option1 value1...]
-    
-    boxmaker.py <basename> [+boolean_option -other_boolean_option]
-    same as
-    boxmaker.py <basename> [boolean_option on other_boolean_option off]
-    
-==========================================================
-
-If existing boxmaker reads boxmaker.<basename> as configuration file. The
-syntax used is:
-
-# comment line
-option1 = value1
-option2 = value2
-...
-
-Note that shortcuts rather than actual option names can be used at all times,
-however this is not recommended in the configuration file for clarities sake.
-
-Options with units will be converted to the system specified by the
-<basename>.tremolo file if autodim=on. If the value is preceeded by ! the unit
-convertion can be switched off for this specific value.
- 
-o List of name-value options:
-
-tremofiledir
-    (Optional if autodim=off)
-    Shortcut: tf
-    Default: ./
-    
-    <basename>.tremolo is needed to dertermine the targed system of units. tf
-    specifies where to find the file.
-    
-potentialsfiledir
-    Shortcut: pf
-    Default: ./
-    
-    <basename>.potentials is needed internally for MoleCuilders element
-    mapping. Also, if automass=on, it's needed to automatically determine the
-    input molecules molar mass.
-    pf specifies where to find the file.
-    
-outfilename
-    Shortcut: o
-    Default: out
-    
-    The name stem of the output files. By default its out.xyz and out.data
-
-source
-    Shortcut: i
-    Default: None
-    
-    The full path to the molecule file used to fill the box. Supports any format
-    MoleCuilder does.
-    
-molarmass
-    (Optional if automass=on)
-    Shortcut: m
-    Default: None
-    
-    Specify the molar mass of the input molecule. Value with unit.
-    
-    E.g.: molarmass = 23.45e-3 kg/mol
-    E.g.: molarmass = !66.3333
-    
-density
-    Shortcut: rho
-    Default: None
-    
-    Specify the desired density of the box. Value with unit.
-    
-temp
-    (Optional)
-    Shortcut: t
-    Default: None
-    
-    If specified and postprocessing is on, the resulting data-file is given an
-    additional
-    
-    # INPUTCONV temp <converted value>
-    
-    header-line. Value with unit.
-
-number
-    Shortcut: n
-    Default: 1000
-
-    How many molecules is the box supposed to contain? Might be internally
-    changed if cubicdomain=on.
-    
-    If number is a vector the box is filled by x*y*z molecules, ignoring
-    the option cubicdomain.
-    
-    E.g.: number = 4 3 9
-    
-o List of boolean options:
-
-cubicdomain
-    Shortcut: cd
-    Default: on
-    
-    If on the box is filled with n*n*n molecules where n is the nearest power
-    of 3 to fit number. Ignored if number is a vector. 
-    
-cubiccell
-    Shortcut: cc
-    Default: off
-    
-    Normally the cuboid of an elementary cell is the input molecules bounding
-    box, scaled to fit the desired molecular volume. If on the elementary cells
-    strictly cubic. Its the only way to archive a cubic simulation area (given
-    cubicdomain is on), but its very likely that molecules will overlap unless
-    its near cubic.
-    
-autorotate
-    Shortcut: ar
-    Default: off
-    
-    Uses MoleCuilder to rotate the input molecule in a way such that the
-    bouding box' volume is minimized, leading to a higher possible density
-    without overlap.
-    
-autodim
-    Shortcut: ad
-    Default: on
-    
-    If on units will be converted to the system specified in the tremolo-file.
-    
-postprocess
-    Shortcut: pp
-    Default: on
-    
-    Adds "# INPUTCONV shift center" to the resulting data file. If a
-    temperature is given its added as well.
-    
-automass
-    Shortcut: am
-    Default: on
-    
-    If specified boxmaker tries to determine the molar mass using the
-    <basename>.potentials file.
Index: utils/Makefile.am
===================================================================
--- utils/Makefile.am	(revision c015b3946b9bb714ae6740f4fbfd3378234a0404)
+++ utils/Makefile.am	(revision d08ab389fd2efbb426bd7cda87ea43a90ce9d3f6)
@@ -1,2 +1,3 @@
+EXTRA_DIST =
 BUILT_SOURCES =
 CLEANFILES =
@@ -4,16 +5,4 @@
 pyexec_SCRIPTS =
 
-if CONDPYTHON
-PYTHON_TOOLS = \
-	boxmaker
-endif
-
-${PYTHON_TOOLS}: python_wrapper
-	cp $< $@
-
-if CONDPYTHON
-BUILT_SOURCES += ${PYTHON_TOOLS}
-CLEANFILES += ${PYTHON_TOOLS}
-bin_SCRIPTS += ${PYTHON_TOOLS}
-pyexec_SCRIPTS += boxmaker.py
-endif
+include Bash/Makefile.am
+include Python/Makefile.am
Index: utils/Python/HOWTO-boxmaker
===================================================================
--- utils/Python/HOWTO-boxmaker	(revision d08ab389fd2efbb426bd7cda87ea43a90ce9d3f6)
+++ utils/Python/HOWTO-boxmaker	(revision d08ab389fd2efbb426bd7cda87ea43a90ce9d3f6)
@@ -0,0 +1,146 @@
+Boxmaker creates boxes of specific density filled with molecules
+
+==========================================================
+
+Usage:
+    boxmaker.py <basename> [option1 value1...]
+    
+    boxmaker.py <basename> [+boolean_option -other_boolean_option]
+    same as
+    boxmaker.py <basename> [boolean_option on other_boolean_option off]
+    
+==========================================================
+
+If existing boxmaker reads boxmaker.<basename> as configuration file. The
+syntax used is:
+
+# comment line
+option1 = value1
+option2 = value2
+...
+
+Note that shortcuts rather than actual option names can be used at all times,
+however this is not recommended in the configuration file for clarities sake.
+
+Options with units will be converted to the system specified by the
+<basename>.tremolo file if autodim=on. If the value is preceeded by ! the unit
+convertion can be switched off for this specific value.
+ 
+o List of name-value options:
+
+tremofiledir
+    (Optional if autodim=off)
+    Shortcut: tf
+    Default: ./
+    
+    <basename>.tremolo is needed to dertermine the targed system of units. tf
+    specifies where to find the file.
+    
+potentialsfiledir
+    Shortcut: pf
+    Default: ./
+    
+    <basename>.potentials is needed internally for MoleCuilders element
+    mapping. Also, if automass=on, it's needed to automatically determine the
+    input molecules molar mass.
+    pf specifies where to find the file.
+    
+outfilename
+    Shortcut: o
+    Default: out
+    
+    The name stem of the output files. By default its out.xyz and out.data
+
+source
+    Shortcut: i
+    Default: None
+    
+    The full path to the molecule file used to fill the box. Supports any format
+    MoleCuilder does.
+    
+molarmass
+    (Optional if automass=on)
+    Shortcut: m
+    Default: None
+    
+    Specify the molar mass of the input molecule. Value with unit.
+    
+    E.g.: molarmass = 23.45e-3 kg/mol
+    E.g.: molarmass = !66.3333
+    
+density
+    Shortcut: rho
+    Default: None
+    
+    Specify the desired density of the box. Value with unit.
+    
+temp
+    (Optional)
+    Shortcut: t
+    Default: None
+    
+    If specified and postprocessing is on, the resulting data-file is given an
+    additional
+    
+    # INPUTCONV temp <converted value>
+    
+    header-line. Value with unit.
+
+number
+    Shortcut: n
+    Default: 1000
+
+    How many molecules is the box supposed to contain? Might be internally
+    changed if cubicdomain=on.
+    
+    If number is a vector the box is filled by x*y*z molecules, ignoring
+    the option cubicdomain.
+    
+    E.g.: number = 4 3 9
+    
+o List of boolean options:
+
+cubicdomain
+    Shortcut: cd
+    Default: on
+    
+    If on the box is filled with n*n*n molecules where n is the nearest power
+    of 3 to fit number. Ignored if number is a vector. 
+    
+cubiccell
+    Shortcut: cc
+    Default: off
+    
+    Normally the cuboid of an elementary cell is the input molecules bounding
+    box, scaled to fit the desired molecular volume. If on the elementary cells
+    strictly cubic. Its the only way to archive a cubic simulation area (given
+    cubicdomain is on), but its very likely that molecules will overlap unless
+    its near cubic.
+    
+autorotate
+    Shortcut: ar
+    Default: off
+    
+    Uses MoleCuilder to rotate the input molecule in a way such that the
+    bouding box' volume is minimized, leading to a higher possible density
+    without overlap.
+    
+autodim
+    Shortcut: ad
+    Default: on
+    
+    If on units will be converted to the system specified in the tremolo-file.
+    
+postprocess
+    Shortcut: pp
+    Default: on
+    
+    Adds "# INPUTCONV shift center" to the resulting data file. If a
+    temperature is given its added as well.
+    
+automass
+    Shortcut: am
+    Default: on
+    
+    If specified boxmaker tries to determine the molar mass using the
+    <basename>.potentials file.
Index: utils/Python/Makefile.am
===================================================================
--- utils/Python/Makefile.am	(revision d08ab389fd2efbb426bd7cda87ea43a90ce9d3f6)
+++ utils/Python/Makefile.am	(revision d08ab389fd2efbb426bd7cda87ea43a90ce9d3f6)
@@ -0,0 +1,15 @@
+if CONDPYTHON
+PYTHON_TOOLS = \
+	Python/boxmaker
+endif
+
+${PYTHON_TOOLS}: Python/python_wrapper
+	cp $< $@
+
+if CONDPYTHON
+EXTRA_DIST += Python/HOWTO-boxmaker
+BUILT_SOURCES += ${PYTHON_TOOLS}
+CLEANFILES += ${PYTHON_TOOLS}
+bin_SCRIPTS += ${PYTHON_TOOLS}
+pyexec_SCRIPTS += Python/boxmaker.py
+endif
Index: utils/Python/boxmaker.py.in
===================================================================
--- utils/Python/boxmaker.py.in	(revision d08ab389fd2efbb426bd7cda87ea43a90ce9d3f6)
+++ utils/Python/boxmaker.py.in	(revision d08ab389fd2efbb426bd7cda87ea43a90ce9d3f6)
@@ -0,0 +1,365 @@
+#!@PYTHON@
+
+# Boxmaker 1.0
+# Creates tremolo-datafiles with arbitrary size and specific density from a single input molecule,
+# supporting numerous pre- and postprocessing features such as unit conversion.
+# Gregor Bollerhey - bollerhe@ins.uni-bonn.de
+
+
+import re, os, os.path, sys, operator
+import pyMoleCuilder as mol
+
+avogadro =  6.022143e23
+
+class c_opt():
+    basename = None
+    tremofiledir = './'
+    potentialsfiledir = './'
+    outfilename = 'out'
+
+    source = None
+    molarmass = None
+    density = None
+    temp = None
+
+    number = '1000'
+    
+    cubicdomain = 'on'
+    cubiccell = 'off'
+    autorotate = 'off'
+    autodim = 'on'
+    postprocess = 'on'
+    automass = 'on'
+
+    def update(self, name, value):
+        shortcuts = {'tf': 'temofiledir', 'pf': 'potentialsfiledir', 'o': 'outfilename',
+        'i': 'source', 'm': 'molarmass', 'rho': 'density',
+        't': 'temp', 'n': 'number', 'cd': 'cubicdomain',
+        'cc': 'cubiccell', 'ar': 'autorotate', 'ad': 'autodim',
+        'pp': 'postprocess', 'am': 'automass'}
+        
+        if name in shortcuts:
+            name = shortcuts[name]
+        
+        if name in dir(self):
+            exec('self.%s = "%s"' % (name, value))
+        else:
+            print 'Warning: Unknown option:', name
+
+
+def ReadSettings(opt):
+    # Obtain basename
+    if len(sys.argv) >= 2:
+        opt.basename = sys.argv[1]
+    else:
+        print 'Usage: boxmaker.py <basename> [options]'
+        exit()
+
+    # Read settings file
+    try:
+        with open('boxmaker.' + opt.basename) as f:
+            for line in f:
+                if len(line) > 0 and line[0] != '#':
+                    L, S, R = line.partition('=')
+                    opt.update(L.strip(), R.strip())
+    except IOError:
+        print 'Warning: Configuration file not readable, CLI only'
+
+    # Parse parameters
+    i = 2
+    while i < len(sys.argv):
+        L = sys.argv[i]
+
+        if L[0] in '+-':
+            LN = L[1:]
+
+            if L[0] == '+':
+                R = 'on'
+            else:
+                R = 'off'
+        else:
+            LN = L
+            i += 1
+            R = sys.argv[i]
+        
+        opt.update(LN, R)
+        i += 1
+
+
+def ReadUnits(opt):
+    lines = [] # The file needs to be processed twice, so we save the lines in the first run
+
+    with open(opt.tremofiledir + opt.basename + '.tremolo') as f:
+        for line in f:
+            if len(line) > 0 and line[0] != '#':
+                line = line.strip()
+                lines.append(line)
+
+                if 'systemofunits' in line:
+                    L, S, SOU = line.partition('=')
+                    SOU = SOU.strip()[:-1] # Remove semicolon
+
+    if SOU == 'custom':
+        units = {}
+        quantities = ['length', 'mass', 'temperature']
+
+        for quantity in quantities:
+            units[quantity] = [None, None] # Init with scaling factor and unit 'None'.
+
+        for line in lines:
+            for quantity in quantities:
+                if quantity in line:
+                    L, S, R = line.partition('=')
+                    R = R.strip()[:-1] # Remove semicolon
+
+                    if 'scalingfactor' in line:
+                        units[quantity][0] = float(R)
+                    else:
+                        units[quantity][1] = R
+
+    elif SOU == 'kcalpermole':
+        units = {'length': [1.0, 'angstrom'], 'mass': [1.0, 'u'], 'temperature': [503.556, 'K']}
+
+    elif SOU == 'evolt':
+        units = {'length': [1.0, 'angstrom'], 'mass': [1.0, 'u'], 'temperature': [11604.0, 'K']}
+
+    else: # SI
+        units = {'length': [1.0, 'm'], 'mass': [1.0, 'kg'], 'temperature': [1.0, 'K']}
+
+    return units
+
+
+def ConvertUnits(have, want):
+    if have[0] == '!':
+        return float(have[1:])
+    
+    # Redo with pipes?
+    #sys.stdout.write("units '%s' '%s'\n" % (have, want))
+    ret = os.system("units '%s' '%s' > temp_units_output" % (have, want))
+
+    if ret == 0:
+        with open('temp_units_output') as f:
+            line = f.readline()
+
+        os.system('rm temp_units_output')
+
+        return float(line[3:-1])
+    else:
+        raise NameError('UnitError')
+        
+        
+def GetSourceMolareMass(opt, units):
+    mol.SelectionAllAtoms()
+    mass_sum = mol.AnalysisCalculateMolarMass()
+    have = ("%f atomicmassunit" % mass_sum)
+    want = ("%f*%s" % tuple(units['mass']))
+    return ConvertUnits(have, want)*avogadro
+
+
+def UpdateSettingsAndSource(opt):
+    # Map boolean values
+    boolmap = {'on': True, 'off': False}
+    
+    for name in ['cubicdomain', 'cubiccell', 'autorotate', 'autodim', 'postprocess', 'automass']:
+        value = eval('opt.' + name)
+        
+        if value in boolmap:
+            value = boolmap[value]
+        else:
+            print 'Not a boolean value:', value
+            exit()
+            
+        exec('opt.' + name + '= value')
+
+    # Convert dimensions
+    if opt.autodim:
+        units = ReadUnits(opt)
+
+        if not opt.automass:
+            have = opt.molarmass
+            want = '%f*%s / mol' % tuple(units['mass'])
+            opt.molarmass = ConvertUnits(have, want)
+
+        have = opt.density
+        want = '(%f*%s) ' % tuple(units['mass']) + '/ (%f*%s)**3' % tuple(units['length'])
+        opt.density = ConvertUnits(have, want)
+        
+        if opt.temp:
+            have = opt.temp
+            want = '%f*%s' % tuple(units['temperature'])
+            opt.temp = ConvertUnits(have, want)
+    else:
+        if not opt.automass:
+            opt.molarmass = float(opt.molarmass)
+        
+        opt.density = float(opt.density)
+        
+        if opt.temp:
+            opt.temp = float(opt.temp)
+
+    # Number might be an integer or a 3-vector
+    nvec = opt.number.split()
+    if len(nvec) == 3:
+        opt.number = [0]*3
+
+        for i in range(3):
+            opt.number[i] = int(nvec[i])
+    else:
+        opt.number = int(opt.number)
+        
+    InitialiseSource(opt)
+        
+    # Automatic source mass
+    if opt.automass:
+        opt.molarmass = GetSourceMolareMass(opt, units)
+        print '======== MOLAR MASS:', opt.molarmass
+
+
+def FindBestCube(opt):
+    newroot = int( round(opt.number**(1./3)) )
+    newnumber = newroot**3
+
+    if newnumber != opt.number:
+        print 'Warning: Number changed to %d.' % newnumber
+
+    return [newroot] * 3
+
+
+def FindBestCuboid(opt):
+    n = opt.number
+
+    # Prime factors of n
+    factors = []
+
+    for i in [2, 3]:
+        while n % i == 0:
+            factors.append(i)
+            n /= 2
+
+    t = 5
+    diff = 2
+
+    while t*t <= n:
+        while n % t == 0:
+            factors.append(t)
+            n /= t
+
+        t = t + diff
+        diff = 6 - diff
+
+    if n > 1:
+        factors.append(n)
+
+    # Even distribution of current biggest prime to each vector -> similar sizes
+    if len(factors) < 3:
+        print 'Warning: Not enough prime factors - falling back to cubic placement'
+        return FindBestCube(opt)
+
+    factors.sort()
+    distri = [[],[],[]]
+    current = 0
+
+    for factor in factors:
+        distri[current].append(factor)
+        current += 1
+        if current == 3:
+            current = 0
+
+    result = [0]*3
+
+    print '======== CUBOID USED:',
+
+    for i in range(3):
+        result[i] = int( reduce(operator.mul, distri[i]) )
+
+    print result
+    return result
+
+
+def GetSourceBBabs(opt):
+    mol.WorldCenterOnEdge()
+    bb = mol.AnalysisCalculateBoundingBox()
+    bbmin = [bb[0], bb[2], bb[4]]
+    bbmax = [bb[1], bb[3], bb[5]]
+
+    bb = [0.0]*3
+
+    for i in range(3):
+        bb[i] = abs(bbmax[i] - bbmin[i])
+
+    return bb
+    
+    
+def InitialiseSource(opt):
+    potfilepath = opt.potentialsfiledir + opt.basename + '.potentials'
+    mol.ParserParseTremoloPotentials(potfilepath)
+    mol.MoleculeLoad(opt.source)
+    
+    if opt.autorotate:
+        mol.SelectAllAtoms()
+        mol.RotateToPrincipalAxisSystem("0 1 0")
+
+# Global options with sensible default parameters
+opt = c_opt()
+
+ReadSettings(opt)
+UpdateSettingsAndSource(opt)
+
+if type(opt.number) == type([]):
+    # Number is a vector - use it without any modification
+    nbox = opt.number
+else:
+    if opt.cubicdomain:
+        nbox = FindBestCube(opt)
+    else:
+        nbox = FindBestCuboid(opt)
+
+VolumePerMolecule = opt.molarmass / (avogadro * opt.density)
+cell = [VolumePerMolecule**(1./3)] * 3
+
+if not opt.cubiccell:
+    try:
+        bb = GetSourceBBabs(opt)
+        print '======== BBOX:', bb
+        # Scaling factor - the molecules bounding box is scaled to fit the volume suiting the density
+        s = (VolumePerMolecule / (bb[0]*bb[1]*bb[2])) ** (1./3)
+
+        if s < 1:
+            print 'Warning: Molecular cells will overlap.'
+
+        for i in range(3):
+            cell[i] = bb[i]*s
+    except ZeroDivisionError:
+        print 'Warning:  Singularity in bounding box, falling back to cubic cell.'
+        
+
+print '======== CELL: ', cell
+
+mol.CommandVerbose('0')
+mol.WorldCenterInBox('%f 0 0 %f 0 %f' % tuple(cell))
+mol.WorldRepeatBox('%d %d %d' % tuple(nbox))
+mol.WorldOutput(opt.outfilename + '.data')
+mol.WorldOutput(opt.outfilename + '.xyz')
+
+domain = [0.0]*3
+
+for i in range(3):
+    domain[i] = cell[i]*nbox[i]
+
+print  '======== DOMAIN: ', domain
+
+# Postprocessing
+
+if opt.postprocess:
+    with open(opt.outfilename + '.data') as f:
+        ofile = f.read()
+    
+    with open(opt.outfilename + '.data', 'w') as f:
+        f.write('# INPUTCONV shift center\n')
+        
+        if opt.temp:
+            f.write('# INPUTCONV temp %.4f\n' % opt.temp)
+            
+        f.write(ofile)
+        
+os.system('rm temp_source.data temp_source.xyz')
Index: utils/Python/python_wrapper.in
===================================================================
--- utils/Python/python_wrapper.in	(revision d08ab389fd2efbb426bd7cda87ea43a90ce9d3f6)
+++ utils/Python/python_wrapper.in	(revision d08ab389fd2efbb426bd7cda87ea43a90ce9d3f6)
@@ -0,0 +1,16 @@
+#! /bin/sh
+#
+# Script taken from Trond Norbye (Couchbase.com) with small modifications.
+#
+# This script is intended to be copied to foo if python script is called foo.py
+# and will call same-named script with exported and correctly set PYTHONPATH.
+
+prefix="@prefix@"
+exec_prefix="@exec_prefix@"
+if test -z "${PYTHONPATH}"; then
+   PYTHONPATH=@pyexecdir@
+else
+   PYTHONPATH=@pyexecdir@:${PYTHONPATH}
+fi
+export PYTHONPATH
+exec @pyexecdir@/`basename $0`.py "$@"
Index: utils/boxmaker.py.in
===================================================================
--- utils/boxmaker.py.in	(revision c015b3946b9bb714ae6740f4fbfd3378234a0404)
+++ 	(revision )
@@ -1,365 +1,0 @@
-#!@PYTHON@
-
-# Boxmaker 1.0
-# Creates tremolo-datafiles with arbitrary size and specific density from a single input molecule,
-# supporting numerous pre- and postprocessing features such as unit conversion.
-# Gregor Bollerhey - bollerhe@ins.uni-bonn.de
-
-
-import re, os, os.path, sys, operator
-import pyMoleCuilder as mol
-
-avogadro =  6.022143e23
-
-class c_opt():
-    basename = None
-    tremofiledir = './'
-    potentialsfiledir = './'
-    outfilename = 'out'
-
-    source = None
-    molarmass = None
-    density = None
-    temp = None
-
-    number = '1000'
-    
-    cubicdomain = 'on'
-    cubiccell = 'off'
-    autorotate = 'off'
-    autodim = 'on'
-    postprocess = 'on'
-    automass = 'on'
-
-    def update(self, name, value):
-        shortcuts = {'tf': 'temofiledir', 'pf': 'potentialsfiledir', 'o': 'outfilename',
-        'i': 'source', 'm': 'molarmass', 'rho': 'density',
-        't': 'temp', 'n': 'number', 'cd': 'cubicdomain',
-        'cc': 'cubiccell', 'ar': 'autorotate', 'ad': 'autodim',
-        'pp': 'postprocess', 'am': 'automass'}
-        
-        if name in shortcuts:
-            name = shortcuts[name]
-        
-        if name in dir(self):
-            exec('self.%s = "%s"' % (name, value))
-        else:
-            print 'Warning: Unknown option:', name
-
-
-def ReadSettings(opt):
-    # Obtain basename
-    if len(sys.argv) >= 2:
-        opt.basename = sys.argv[1]
-    else:
-        print 'Usage: boxmaker.py <basename> [options]'
-        exit()
-
-    # Read settings file
-    try:
-        with open('boxmaker.' + opt.basename) as f:
-            for line in f:
-                if len(line) > 0 and line[0] != '#':
-                    L, S, R = line.partition('=')
-                    opt.update(L.strip(), R.strip())
-    except IOError:
-        print 'Warning: Configuration file not readable, CLI only'
-
-    # Parse parameters
-    i = 2
-    while i < len(sys.argv):
-        L = sys.argv[i]
-
-        if L[0] in '+-':
-            LN = L[1:]
-
-            if L[0] == '+':
-                R = 'on'
-            else:
-                R = 'off'
-        else:
-            LN = L
-            i += 1
-            R = sys.argv[i]
-        
-        opt.update(LN, R)
-        i += 1
-
-
-def ReadUnits(opt):
-    lines = [] # The file needs to be processed twice, so we save the lines in the first run
-
-    with open(opt.tremofiledir + opt.basename + '.tremolo') as f:
-        for line in f:
-            if len(line) > 0 and line[0] != '#':
-                line = line.strip()
-                lines.append(line)
-
-                if 'systemofunits' in line:
-                    L, S, SOU = line.partition('=')
-                    SOU = SOU.strip()[:-1] # Remove semicolon
-
-    if SOU == 'custom':
-        units = {}
-        quantities = ['length', 'mass', 'temperature']
-
-        for quantity in quantities:
-            units[quantity] = [None, None] # Init with scaling factor and unit 'None'.
-
-        for line in lines:
-            for quantity in quantities:
-                if quantity in line:
-                    L, S, R = line.partition('=')
-                    R = R.strip()[:-1] # Remove semicolon
-
-                    if 'scalingfactor' in line:
-                        units[quantity][0] = float(R)
-                    else:
-                        units[quantity][1] = R
-
-    elif SOU == 'kcalpermole':
-        units = {'length': [1.0, 'angstrom'], 'mass': [1.0, 'u'], 'temperature': [503.556, 'K']}
-
-    elif SOU == 'evolt':
-        units = {'length': [1.0, 'angstrom'], 'mass': [1.0, 'u'], 'temperature': [11604.0, 'K']}
-
-    else: # SI
-        units = {'length': [1.0, 'm'], 'mass': [1.0, 'kg'], 'temperature': [1.0, 'K']}
-
-    return units
-
-
-def ConvertUnits(have, want):
-    if have[0] == '!':
-        return float(have[1:])
-    
-    # Redo with pipes?
-    #sys.stdout.write("units '%s' '%s'\n" % (have, want))
-    ret = os.system("units '%s' '%s' > temp_units_output" % (have, want))
-
-    if ret == 0:
-        with open('temp_units_output') as f:
-            line = f.readline()
-
-        os.system('rm temp_units_output')
-
-        return float(line[3:-1])
-    else:
-        raise NameError('UnitError')
-        
-        
-def GetSourceMolareMass(opt, units):
-    mol.SelectionAllAtoms()
-    mass_sum = mol.AnalysisCalculateMolarMass()
-    have = ("%f atomicmassunit" % mass_sum)
-    want = ("%f*%s" % tuple(units['mass']))
-    return ConvertUnits(have, want)*avogadro
-
-
-def UpdateSettingsAndSource(opt):
-    # Map boolean values
-    boolmap = {'on': True, 'off': False}
-    
-    for name in ['cubicdomain', 'cubiccell', 'autorotate', 'autodim', 'postprocess', 'automass']:
-        value = eval('opt.' + name)
-        
-        if value in boolmap:
-            value = boolmap[value]
-        else:
-            print 'Not a boolean value:', value
-            exit()
-            
-        exec('opt.' + name + '= value')
-
-    # Convert dimensions
-    if opt.autodim:
-        units = ReadUnits(opt)
-
-        if not opt.automass:
-            have = opt.molarmass
-            want = '%f*%s / mol' % tuple(units['mass'])
-            opt.molarmass = ConvertUnits(have, want)
-
-        have = opt.density
-        want = '(%f*%s) ' % tuple(units['mass']) + '/ (%f*%s)**3' % tuple(units['length'])
-        opt.density = ConvertUnits(have, want)
-        
-        if opt.temp:
-            have = opt.temp
-            want = '%f*%s' % tuple(units['temperature'])
-            opt.temp = ConvertUnits(have, want)
-    else:
-        if not opt.automass:
-            opt.molarmass = float(opt.molarmass)
-        
-        opt.density = float(opt.density)
-        
-        if opt.temp:
-            opt.temp = float(opt.temp)
-
-    # Number might be an integer or a 3-vector
-    nvec = opt.number.split()
-    if len(nvec) == 3:
-        opt.number = [0]*3
-
-        for i in range(3):
-            opt.number[i] = int(nvec[i])
-    else:
-        opt.number = int(opt.number)
-        
-    InitialiseSource(opt)
-        
-    # Automatic source mass
-    if opt.automass:
-        opt.molarmass = GetSourceMolareMass(opt, units)
-        print '======== MOLAR MASS:', opt.molarmass
-
-
-def FindBestCube(opt):
-    newroot = int( round(opt.number**(1./3)) )
-    newnumber = newroot**3
-
-    if newnumber != opt.number:
-        print 'Warning: Number changed to %d.' % newnumber
-
-    return [newroot] * 3
-
-
-def FindBestCuboid(opt):
-    n = opt.number
-
-    # Prime factors of n
-    factors = []
-
-    for i in [2, 3]:
-        while n % i == 0:
-            factors.append(i)
-            n /= 2
-
-    t = 5
-    diff = 2
-
-    while t*t <= n:
-        while n % t == 0:
-            factors.append(t)
-            n /= t
-
-        t = t + diff
-        diff = 6 - diff
-
-    if n > 1:
-        factors.append(n)
-
-    # Even distribution of current biggest prime to each vector -> similar sizes
-    if len(factors) < 3:
-        print 'Warning: Not enough prime factors - falling back to cubic placement'
-        return FindBestCube(opt)
-
-    factors.sort()
-    distri = [[],[],[]]
-    current = 0
-
-    for factor in factors:
-        distri[current].append(factor)
-        current += 1
-        if current == 3:
-            current = 0
-
-    result = [0]*3
-
-    print '======== CUBOID USED:',
-
-    for i in range(3):
-        result[i] = int( reduce(operator.mul, distri[i]) )
-
-    print result
-    return result
-
-
-def GetSourceBBabs(opt):
-    mol.WorldCenterOnEdge()
-    bb = mol.AnalysisCalculateBoundingBox()
-    bbmin = [bb[0], bb[2], bb[4]]
-    bbmax = [bb[1], bb[3], bb[5]]
-
-    bb = [0.0]*3
-
-    for i in range(3):
-        bb[i] = abs(bbmax[i] - bbmin[i])
-
-    return bb
-    
-    
-def InitialiseSource(opt):
-    potfilepath = opt.potentialsfiledir + opt.basename + '.potentials'
-    mol.ParserParseTremoloPotentials(potfilepath)
-    mol.MoleculeLoad(opt.source)
-    
-    if opt.autorotate:
-        mol.SelectAllAtoms()
-        mol.RotateToPrincipalAxisSystem("0 1 0")
-
-# Global options with sensible default parameters
-opt = c_opt()
-
-ReadSettings(opt)
-UpdateSettingsAndSource(opt)
-
-if type(opt.number) == type([]):
-    # Number is a vector - use it without any modification
-    nbox = opt.number
-else:
-    if opt.cubicdomain:
-        nbox = FindBestCube(opt)
-    else:
-        nbox = FindBestCuboid(opt)
-
-VolumePerMolecule = opt.molarmass / (avogadro * opt.density)
-cell = [VolumePerMolecule**(1./3)] * 3
-
-if not opt.cubiccell:
-    try:
-        bb = GetSourceBBabs(opt)
-        print '======== BBOX:', bb
-        # Scaling factor - the molecules bounding box is scaled to fit the volume suiting the density
-        s = (VolumePerMolecule / (bb[0]*bb[1]*bb[2])) ** (1./3)
-
-        if s < 1:
-            print 'Warning: Molecular cells will overlap.'
-
-        for i in range(3):
-            cell[i] = bb[i]*s
-    except ZeroDivisionError:
-        print 'Warning:  Singularity in bounding box, falling back to cubic cell.'
-        
-
-print '======== CELL: ', cell
-
-mol.CommandVerbose('0')
-mol.WorldCenterInBox('%f 0 0 %f 0 %f' % tuple(cell))
-mol.WorldRepeatBox('%d %d %d' % tuple(nbox))
-mol.WorldOutput(opt.outfilename + '.data')
-mol.WorldOutput(opt.outfilename + '.xyz')
-
-domain = [0.0]*3
-
-for i in range(3):
-    domain[i] = cell[i]*nbox[i]
-
-print  '======== DOMAIN: ', domain
-
-# Postprocessing
-
-if opt.postprocess:
-    with open(opt.outfilename + '.data') as f:
-        ofile = f.read()
-    
-    with open(opt.outfilename + '.data', 'w') as f:
-        f.write('# INPUTCONV shift center\n')
-        
-        if opt.temp:
-            f.write('# INPUTCONV temp %.4f\n' % opt.temp)
-            
-        f.write(ofile)
-        
-os.system('rm temp_source.data temp_source.xyz')
Index: utils/python_wrapper.in
===================================================================
--- utils/python_wrapper.in	(revision c015b3946b9bb714ae6740f4fbfd3378234a0404)
+++ 	(revision )
@@ -1,16 +1,0 @@
-#! /bin/sh
-#
-# Script taken from Trond Norbye (Couchbase.com) with small modifications.
-#
-# This script is intended to be copied to foo if python script is called foo.py
-# and will call same-named script with exported and correctly set PYTHONPATH.
-
-prefix="@prefix@"
-exec_prefix="@exec_prefix@"
-if test -z "${PYTHONPATH}"; then
-   PYTHONPATH=@pyexecdir@
-else
-   PYTHONPATH=@pyexecdir@:${PYTHONPATH}
-fi
-export PYTHONPATH
-exec @pyexecdir@/`basename $0`.py "$@"
