Changeset 1208 for branches/sandbox
 Timestamp:
 Aug 12, 2012 10:42:44 PM (8 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

branches/sandbox/readexp.tcl
r1189 r1208 4309 4309 } 4310 4310 4311 # return a list of defined Fourier maps 4312 proc listFourier {} { 4313 set l {} 4314 foreach i {1 2 3 4 5 6 7 8 9} { 4315 if {[existsexp " FOUR CDAT$i"]} { 4316 lappend l $i 4317 } 4318 } 4319 return $l 4320 } 4321 4322 # read a Fourier map entry 4323 # returns five values: 4324 # 0: type of map (DELF,FCLC,FOBS,NFDF,PTSN,DPTS) 4325 # 1: section (X,Y or Z) 4326 # 2: phase (19) 4327 # 3: DMIN (usually 0.0) 4328 # 4: DMAX (usually 999.99) 4329 proc readFourier {num} { 4330 set key " FOUR CDAT$num" 4331 if {![existsexp $key]} { 4332 return {} 4333 } 4334 set vals {} 4335 # 0: type of map (DELF,FCLC,FOBS,NFDF,PTSN,DPTS) 4336 lappend vals [string trim [string range [readexp $key] 2 6]] 4337 # 1: section (X,Y or Z) 4338 lappend vals [string trim [string range [readexp $key] 7 8]] 4339 # 2: phase (19) 4340 lappend vals [string trim [string range [readexp $key] 8 13]] 4341 # 3: DMIN (usually 0.0) 4342 lappend vals [string trim [string range [readexp $key] 18 25]] 4343 # 4: DMAX (usually 999.99) 4344 lappend vals [string trim [string range [readexp $key] 30 37]] 4345 return $vals 4346 } 4347 4348 # add a new Fourier map computation type 4349 # arguments: 4350 # phase: (19) 4351 # type: type of map (DELF,FCLC,FOBS,NFDF,PTSN,DPTS)  default DELF 4352 # section: (X,Y or Z)  default Z 4353 proc addFourier {phase {type "DELF"} {section "Z"}} { 4354 set num {} 4355 foreach i {1 2 3 4 5 6 7 8 9} { 4356 set key " FOUR CDAT$i" 4357 if {! [existsexp " FOUR CDAT$i"]} { 4358 set num $i 4359 break 4360 } 4361 } 4362 if {$num == ""} {return {}} 4363 set key " FOUR CDAT$num" 4364 makeexprec $key 4365 setexp $key $type 3 4 4366 setexp $key $section 8 1 4367 validint phase 5 4368 setexp $key $phase 9 5 4369 setexp $key "NOPR 0.00 999.99" 15 23 4370 return $num 4371 } 4372 4373 # read/set a Fourier computation value 4374 # use: Fourierinfo num parm 4375 # or: Fourierinfo num parm set value 4376 # 4377 # num is the Fourier entry 4378 # parm is one of the following 4379 # type  type of map (DELF,FCLC,FOBS,NFDF,PTSN,DPTS) 4380 # section  last running map direction (X,Y or Z) 4381 # phase  phase (19) 4382 # dmin  dspace for highest order reflection to use (usually 0.0) 4383 # dmax  dspace for lowest order reflection to use (usually 999.99) 4384 # all parameters may be read or set 4385 proc Fourierinfo {num parm "action get" "value {}"} { 4386 set key " FOUR CDAT$num" 4387 if {![existsexp $key]} { 4388 return {} 4389 } 4390 switch glob ${parm}$action { 4391 typeget { 4392 # type of map (DELF,FCLC,FOBS,NFDF,PTSN,DPTS) 4393 return [string range [readexp $key] 2 6] 4394 } 4395 typeset { 4396 set found 0 4397 foreach val {DELF FCLC FOBS NFDF PTSN DPTS} { 4398 if {$val == $value} { 4399 set found 1 4400 break 4401 } 4402 } 4403 if $found { 4404 setexp $key $value 3 4 4405 } 4406 } 4407 sectionget { 4408 # section (X,Y or Z) 4409 return [string range [readexp $key] 7 8] 4410 } 4411 sectionset { 4412 set found 0 4413 foreach val {X Y Z} { 4414 if {$val == $value} { 4415 set found 1 4416 break 4417 } 4418 } 4419 if $found { 4420 setexp $key $value 8 1 4421 } 4422 } 4423 phaseget { 4424 # phase (19) 4425 return [string range [readexp $key] 8 13] 4426 } 4427 phaseset { 4428 validint value 5 4429 setexp $key $value 9 5 4430 } 4431 dminget { 4432 # DMIN (usually 0.0) 4433 return [string range [readexp $key] 18 25] 4434 } 4435 dminset { 4436 validreal value 7 2 4437 setexp $key $value 19 7 4438 } 4439 dmaxget { 4440 # DMAX (usually 999.99) 4441 return [string range [readexp $key] 30 37] 4442 } 4443 dmaxset { 4444 validreal value 7 2 4445 setexp $key $value 31 7 4446 } 4447 default { 4448 set msg "Unsupported Fourierinfo access: parm=$parm action=$action" 4449 puts $msg 4450 tk_dialog .badexp "Error in readexp" $msg error 0 Exit 4451 } 4452 } 4453 } 4454 4455 # set histograms used in Fourier computation 4456 # use: 4457 # FourierHists $phase 4458 # FourierHists $phase set {4 3 2 1} 4459 # returns a list of histograms to be used to compute that phase's Fourier map 4460 # or sets a list of histograms to be used to compute that phase's Fourier map 4461 # 4462 # Note that the histograms are loaded in the order specified with reflections in 4463 # the last histogram overwriting those in earlier ones, where a reflection 4464 # occurs in more than one place 4465 proc FourierHists {phase "action get" "value {}"} { 4466 # note that in theory one can have more than one CRSm FMHSTn record 4467 # if more than 22 histograms are used but we will ignore this 4468 set key "CRS$phase FMHST1" 4469 if {![existsexp $key]} { 4470 makeexprec $key 4471 } 4472 if {$action == "get"} { 4473 return [string trim [readexp $key]] 4474 } else { 4475 set hlist {} 4476 foreach hist $value { 4477 validint hist 3 4478 append hlist $hist 4479 } 4480 setexp $key $hlist 0 67 4481 } 4482 } 4483 # get the Fourier map computation step and limits 4484 # returns 4 lists: 4485 # {stepx stepy stepz} : step size in Angstroms 4486 # {xmin xmax} : min and max x in fractional coordinates 4487 # {ymin ymax} : min and max y in fractional coordinates 4488 # {zmin zmax} : min and max z in fractional coordinates 4489 proc getFourierLimits {phase} { 4490 set key "CRS$phase FMPCTL" 4491 if {![existsexp $key]} { 4492 makeexprec $key 4493 } 4494 set i 0 4495 set line [readexp $key] 4496 foreach v {x y z} cell {a b c} { 4497 set cell_$v [phaseinfo $phase $cell] 4498 } 4499 foreach typ {step min max} { 4500 foreach v {x y z} { 4501 set val [string trim [string range $line $i [expr $i+5]]] 4502 if {$val = ""} {set val 0} 4503 set ${typ}_${v} $val 4504 incr i 5 4505 } 4506 } 4507 set steps {} 4508 foreach v {x y z} { 4509 set range_$v {} 4510 lappend steps [expr {[set cell_$v] / [set step_$v]}] 4511 lappend range_$v [expr {[set min_$v] * 1. / [set step_$v] }] 4512 lappend range_$v [expr {[set max_$v] * 1. / [set step_$v] }] 4513 } 4514 return [list $steps $range_x $range_y $range_z] 4515 } 4516 4517 # set the Fourier map computation step and limits 4518 # Asteps contains {stepx stepy stepz} : step size in Angstroms 4519 # range_x contains {xmin xmax} : min and max x in fractional coordinates 4520 # range_y contains {ymin ymax} : min and max y in fractional coordinates 4521 # range_z contains {zmin zmax} : min and max z in fractional coordinates 4522 proc setFourierLimits {phase Asteps range_x range_y range_z} { 4523 set key "CRS$phase FMPCTL" 4524 if {![existsexp $key]} { 4525 makeexprec $key 4526 } 4527 set i 1 4528 foreach v {x y z} cell {a b c} As $Asteps { 4529 set s [expr {1 + int([phaseinfo $phase $cell] / $As)}] 4530 set s [expr {$s + ($s % 2)}] 4531 set step_$v $s 4532 lappend steps [set step_$v] 4533 validint s 5 4534 setexp $key $s $i 5 4535 incr i 5 4536 } 4537 foreach v {x y z} { 4538 foreach {min max} [set range_$v] {} 4539 set s [expr {int($min * [set step_$v].5)}] 4540 validint s 5 4541 setexp $key $s $i 5 4542 incr i 5 4543 set s [expr {int($max * [set step_$v]+.5)}] 4544 validint s 5 4545 setexp $key $s $i 5 4546 incr i 5 4547 } 4548 }
Note: See TracChangeset
for help on using the changeset viewer.