Source code for schrodinger.application.macromodel.tools
"""
Useful functions for setting up MacroModel jobs.
Copyright Schrodinger, LLC. All rights reserved.
"""
# Contributors: K Shawn Watts
################################################################################
# Globals/Constants
################################################################################
################################################################################
# Packages
################################################################################
import os
import re
_version = '$Revision: 1.8.12.1 $'
################################################################################
# Functions
################################################################################
[docs]def count(mae_file=""):
"""
Returns the total number of structures in a Maestro file.
Uses structure.count_structures when possible.
"""
try:
import schrodinger.structure as structure
return structure.count_structures(mae_file)
except ImportError:
return _count(mae_file)
def _count(mae_file=""):
"""
Deprecated by count.
Returns the total number of full and partial CTs in the file.
This is a simple grep statement that will fail if grep is not
in your path, and worse, will miscount if the CTs have wicked
values that match the [fp]_m_ct pattern.
Replaced by a more robust structure.count_structures.
"""
cmd = r"egrep -c '(}\s+)?[fp]_m_ct' %s" % mae_file
# run command, capture stdout
p = os.popen(cmd, 'r')
count = p.readline()
count = int(count.strip())
p.close()
return count
[docs]def serial_split(mae_file=""):
"""
Returns a list of files generated after executing serial_split.
The user must have the utility, or this will fail. The useful
bit is the returned list of file names.
"""
mae_re = re.compile(r'.mae$')
basename = mae_re.sub("", mae_file)
basename += '_SerNo_'
split_re = re.compile(r'_SerNo_\d+\.mae$')
base_re = re.compile(basename)
serial_split_files = []
# Do the split with the existing utility which is fast, but does
# not return anything useful
cmd = " ".join([
os.path.join(os.environ.get('SCHRODINGER'), 'utilities',
'serial_split'), mae_file, basename
])
# ev45987 fixes for windows
# Do commandline clean up ourselves as described by Aditya
cmd = cmd.replace("\\", "\\\\")
cmd = "%s" % cmd
os.system(cmd)
# Recover the output with some flimsy regexs
for file in os.listdir(os.getcwd()):
if base_re.match(file) and split_re.search(file):
serial_split_files.append(file)
return serial_split_files
################################################################################
# Classes
################################################################################
# Deprecated GUI classes removed r2006-1. Use schrodinger.ui package instead.
#EOF