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 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
|
# Copyright 2006 Joel Bard
# Copyright 2006 by Bernhard Lohkamp
# Copyright 2006 by Paul Emsley, The University of York
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or (at
# your option) any later version.
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor,
# Boston, MA 02110-1301, USA
# Read in cns coeff-data (given filenames) and a pdb molecule filename to make
# maps.
#
def cns2coot(twofofc_coeffs, fofc_coeffs, model_pdb):
import os, string
# remove any trailing spaces of string
# BL says: maybe somthing for coot-utils?
# ..and has already a buikld-in function in python
def trim_trailing_spaces(s):
f = string.rstrip(s)
return f
# return [] on bad, else return a 6 memberes list.
def get_cell_from_pdb(pdb_file):
s = []
fin = False
try:
fin = open(pdb_file,'r')
except IOError:
print("BL WARNING:: Cannot read ", pdb_file)
if (fin):
lines = fin.readlines()
for line in lines:
if "CRYST1" in line:
s = string.split(line)
s = s[1:7]
fin.close()
break
else:
print("BL WARNING:: IOError in ", pdb_file)
return s
# return "" on bad, else return a string that is the space group.
#
# have to go through all sorts of hoops because sometimes we might
# get P 21 and sometimes we might get P 1 21 1 for example
# sftools needs P21, can't handle P1211
# that being said - there must be a better way
# set SYMM1=`awk 'BEGIN { FIELDWIDTHS="55 11 4" } /CRYST1/ {gsub(" ","",$2); coot_utils.printf "%s\n", $2}' $3`
#
def get_symm_from_pdb_file(pdb_file):
s = ""
fin = False
try:
fin = open(pdb_file,'r')
except IOError:
print("BL WARNING:: Cannot read ", pdb_file)
if (fin):
lines = fin.readlines()
for line in lines:
if "CRYST1" in line:
s = string.split(line)
s = s[7:]
s = string.join(s,"")
fin.close()
break
else:
print("BL WARNING:: IOError in ", pdb_file)
return s
def get_symm_from_pdb_file_2(pdb_file):
s = ""
fin = False
try:
fin = open(pdb_file,'r')
except IOError:
print("BL WARNING:: Cannot read ", pdb_file)
if (fin):
lines = fin.readlines()
for line in lines:
if "CRYST1" in line:
s = string.split(line)
s = s[7:]
s = string.join(s)
fin.close()
break
else:
print("BL WARNING:: IOError in ", pdb_file)
return s
# Return a symmetry string
# on problem, return False. Use that to exit (elsewhere).
#
def get_symm_from_symop_lib(symm2):
try:
e = os.environ['CCP4']
except:
print("CCP4 not set up.")
return False
if (e):
s = False
e = os.path.join(e,"lib","data","symop.lib")
fin = False
try:
fin=open(e,'r')
except:
print("Problems opening ", e)
if (fin):
lines = fin.readlines()
for line in lines:
if symm2 in line:
t = string.split(line)
s = t[3]
break
fin.close()
return s
else:
print("Problems with CCP4 set up")
# main body
map1_prefix = coot_utils.strip_extension(twofofc_coeffs)
map2_prefix = coot_utils.strip_extension(fofc_coeffs)
map1_tmp = map1_prefix + "_tmp.pdb"
map2_tmp = map2_prefix + "_tmp.pdb"
cell = get_cell_from_pdb(model_pdb)
print("map1_prefix: ", map1_prefix)
print("map2_prefix: ", map2_prefix)
print("cell: ", cell)
symm1 = get_symm_from_pdb_file(model_pdb)
pdbset_log = "cns2coot-pdbset-tmp.log"
print("symm1: ", symm1)
coot_utils.popen_command("pdbset",["XYZIN",model_pdb,"XYZOUT",map1_tmp],["CELL " + string.join(cell), "SPACEGROUP " + symm1],pdbset_log,0)
symm2 = get_symm_from_pdb_file_2(map1_tmp)
print("symm2: ", symm2)
symm = get_symm_from_symop_lib(symm2)
if not(symm):
print("Failed to find symm in symop.lib!")
else:
print("INFO:: SYMM is ", symm)
map1_mtz = map1_prefix + ".mtz"
map2_mtz = map2_prefix + ".mtz"
map_coot_mtz = map1_prefix + "-coot.mtz"
cad_log = "cns2coot-cad-tmp.log"
sftools_1_log = "cns2coot-sftools-1-tmp.log"
sftools_2_log = "cns2coot-sftools-2-tmp.log"
if os.path.isfile(map1_mtz):
os.remove(map1_mtz)
if os.path.isfile(map2_mtz):
os.remove(map2_mtz)
coot_utils.popen_command("sftools", [] ,["read " + twofofc_coeffs, "cns", string.join(cell), symm, "END", "W", "P", "R", "SET LABELS", "FOM", "PHIC", "SCALE", "FWT", "PHWT", "WRITE " + map1_mtz] , sftools_1_log, 0)
coot_utils.popen_command("sftools", [] ,["read " + fofc_coeffs, "cns", string.join(cell), symm, "END", "W", "P", "R", "SET LABELS", "FOM", "PHIC", "SCALE", "DELFWT", "PHDELWT", "WRITE " + map2_mtz] , sftools_2_log, 0)
coot_utils.popen_command("cad", ["HKLIN1", map1_mtz, "HKLIN2", map2_mtz, "HKLOUT", map_coot_mtz],["LABIN FILE_NUMBER 1 E1=FOM E2=PHIC E3=FWT E4=PHWT", "LABIN FILE_NUMBER 2 E1=DELFWT E2=PHDELWT", "END"], cad_log, 0)
if os.path.isfile(map1_mtz):
os.remove(map1_mtz)
if os.path.isfile(map2_mtz):
os.remove(map2_mtz)
# now load them in Coot
#
coot.read_pdb(model_pdb)
coot.make_and_draw_map_with_reso_with_refmac_params(map_coot_mtz, "FWT", "PHWT", "", 0, 0, 0, "Fobs:None-specified", "SigF:None-specified", "RFree:None-specified", 0, 0, 0, -1.00, -1.00)
coot.make_and_draw_map_with_reso_with_refmac_params(map_coot_mtz, "DELFWT", "DELPHWT", "", 0, 1, 0, "Fobs:None-specified", "SigF:None-specified", "RFree:None-specified", 0, 0, 0, -1.00, -1.00)
#cns_coot("2fo-fc_Fum480.coeff","fo-fc_Fum480.coeff","bindividual_Fum480.pdb")
|