#!/usr/bin/env ccp4-python
import sys
from CCP4pipeline import Control
keywords = """
Input MTZ (post density mod)
Input sequence file
Initial model to extend
Observed F/sigma
HL coeffs
PHI/FOM
Initial map coeffs scaled to F
Free-R flag
Number of build/refine cycles
Reference data
HL coeffs
"""
#
# Nautilus script template (1st cycle)
#
nautilus_1st = ( 'cnautilus', '-stdin', '''
title <=title>
pdbin-ref <=pdbin-ref>
seqin <=seqin>
mtzin <=mtzin>
colin-fo <=colin-fo>
colin-hl <=colin-hl >
colin-phifom <=colin-phifom>
colin-fc <=colin-fc >
colin-free <=colin-free >
pdbin <=pdbin>
pdbout <=build-pdbout>
anisotropy-correction
resolution <=nautilus-resolution>
verbose <=verbose>
<=.>
''' )
#
# Nautilus script template (nth cycle)
#
nautilus_nth = ( 'cnautilus', '-stdin', '''
title <=title>
pdbin-ref <=pdbin-ref>
seqin <=seqin>
mtzin <=refine-mtzout>
colin-fo <=colin-fo>
colin-fc FWT,PHWT
colin-free <=colin-free >
pdbin <=refine-pdbout>
pdbout <=build-pdbout>
anisotropy-correction
resolution <=nautilus-resolution>
verbose <=verbose>
<=.>
''' )
#
# Refmac script template
#
refmac_all = ( 'refmac5', '''
HKLIN <=mtzin> XYZIN <=build-pdbout>
HKLOUT <=refine-mtzout> XYZOUT <=refine-pdbout>
''', '''
title <=title>
ncyc 10
labin -
-
-
HLA=<=colin-hl/list[1]> HLB=<=colin-hl/list[2]> -
HLC=<=colin-hl/list[3]> HLD=<=colin-hl/list[4]> -
-
-
PHIB=<=colin-phifom/list[1]> FOM=<=colin-phifom/list[2]> -
-
-
HLA=<=refmac-colin-hl/list[1]> HLB=<=refmac-colin-hl/list[2]> -
HLC=<=refmac-colin-hl/list[3]> HLD=<=refmac-colin-hl/list[4]> -
-
-
FREE=<=colin-free/list[1]> -
FP=<=colin-fo/list[1]> SIGFP=<=colin-fo/list[2]>
weight MATRIX <=refmac-weight>
weight AUTO
twin
make check NONE
PNAME nautilus
DNAME nautilus
<=.>
END
''' )
#
# Pipeline control program
#
control = Control()
control.parse_input( keywords )
print control.display_params( "nautilus-pipeline v0.3" )
prefix = control.xml.get( "prefix" )
if ( prefix[-1:] == "/" ): control.mkdir( prefix )
control.xml.set( "build-pdbout", prefix+"build.pdb" )
control.xml.set( "refine-pdbout", prefix+"refine.pdb" )
control.xml.set( "refine-mtzout", prefix+"refine.mtz" )
control.run_program_template( nautilus_1st )
control.run_program_template( refmac_all )
for i in range( 1, int(control.xml.get("cycles")) ):
control.run_program_template( nautilus_nth )
control.run_program_template( refmac_all )
control.copy( control.xml.get("refine-pdbout"), control.xml.get("pdbout") )