Skip to content


Subversion checkout URL

You can clone with
Download ZIP
tree: e683fcef6a
Fetching contributors…

Cannot retrieve contributors at this time

executable file 95 lines (77 sloc) 3.479 kB
import subprocess
import os.path
# To change this template, choose Tools | Templates
# and open the template in the editor.
__date__ ="$Jun 29, 2009 10:09:03 AM$"
import os,sys,argparse
class Converter(object):
program = None
# Mask convert maskconvert -i input mask -o outputformat
def __init__(self,toformat=None ,infilepath=None):
self.toformat = toformat
self.infilepath = infilepath
if "linux" in sys.platform:
gotprog = self.__checkformapman("lx_mapman")
if gotprog:
Converter.program = gotprog
print "Using %s for mask conversion" % self.program
elif self.__checkformapman("mapman"):
gotprog = self.__checkformapman("mapman")
Converter.program = gotprog
print "Using %s for mask conversion" % self.program
elif "darwin" in sys.platform:
gotprog = self.__checkformapman("osx_mapman")
if gotprog:
Converter.program = gotprog
print "Using %s for mask conversion" % self.program
elif __checkformapman("mapman"):
gotprog = __checkformapman("mapman")
Converter.program = gotprog
print "Using %s for mask conversion" % self.program
print "Exiting no mapman in path"
def __checkformapman(self,myprogram):
def is_exe(tested_program):
return os.path.exists(tested_program) and os.access(tested_program, os.X_OK)
fpath, fname = os.path.split(myprogram)
if fpath:
if is_exe(os.path.join(fpath,fname)):
program = os.path.join(fpath, fname)
return program
for path in os.environ["PATH"].split(os.pathsep):
exe_file = os.path.join(path, myprogram)
if is_exe(exe_file):
program = exe_file
return program
return None
def convertto(self,format,informat="CCP4"):
print "Converting format to %s using %s " % ( format , self.program)
base,name = os.path.split(self.infilepath)
name_root = os.path.splitext(name)[0]
# The coot file browser does not filter and show files ending with synonymous X-PLOR format
# So converting it to CNS
if format == "X-PLOR":
format = "CNS"
outfile = os.path.join(base,"".join([name_root,".",format.lower()]))
print os.path.join(base, outfile)
if os.path.lexists(self.infilepath):
mapman_scr = """re m1 %s %s\nwr m1 %s %s\nquit\n""" % (self.infilepath,informat,outfile,format)
tmp = open("tmp.scr","w")
a = os.system(self.program + " < tmp.scr ")
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("-i" , dest="infile" ,required=True)
parser.add_argument("-d" , dest="output_format", required=True, choices=["CCP4", "X-PLOR","CNS","OMAP"])
parser.add_argument("-s",dest="input_format",choices=["CCP4", "X-PLOR","CNS","OMAP"])
cli = parser.parse_args()
c = Converter(infilepath=cli.infile)
if cli.input_format:
Jump to Line
Something went wrong with that request. Please try again.