| 1 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2 |
% mcf2graph ver 5.31 Copyright (c) 2013-2026 Akira Yamaji |
| 3 |
% |
| 4 |
% Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
| 5 |
% and associated documentation files (the "Software"), to deal in the Software without restriction, |
| 6 |
% including without limitation the rights to use, copy, modify, merge, publish, distribute, |
| 7 |
% sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
| 8 |
% furnished to do so, subject to the following conditions: |
| 9 |
% |
| 10 |
% The above copyright notice and this permission notice shall be included in all copies |
| 11 |
% or substantial portions of the Software. |
| 12 |
% |
| 13 |
% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,EXPRESS OR IMPLIED, |
| 14 |
% INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE |
| 15 |
% AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
| 16 |
% DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 17 |
% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 18 |
%------------------------------------------------------------------------------------------------- |
| 19 |
% mcf2graph is MetaPost macro package convert Molecular Coding Format(MCF) to graphic file |
| 20 |
% sgv/eps/png/mdl molfile |
| 21 |
% This package is located at : http://www.ctan.org/pkg/mcf2graph |
| 22 |
% Suggestion or request mail to : [email protected] |
| 23 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 24 |
message "* This is mcf2graph ver 5.31 2026.05.24"; |
| 25 |
tracingstats:=1; prologues:=3; |
| 26 |
%------------------------------------------------------------------------------------------------- |
| 27 |
newinternal string EN_,tempc,temps,ts,tc,lines,atoms; |
| 28 |
newinternal numeric nA,nB,nC,nD,nE,nL,nN,nP,nR,nS,nU,nX,nY,nW,pX,pY,pB,pc_int; |
| 29 |
numeric save_num[],pc_x[][],pc_y[][],param_e[][],pc_cnt[],tbl_atom[],tbl_grp[][], |
| 30 |
tbl_atom_wt[],tbl_atom_mi[],tbl_char_wd[],tbl_char_ht[],at_char[],mc_indent[],error_e[], |
| 31 |
error_b[],unit_lines[],unit_info[],lenw[],mc_x[],mc_y[],mc_b[],error_type[]; |
| 32 |
string row[][],save_str[],tbl_atoms[],str_tbl[],arg_s[],mc[],ex[],ad[],op[],tag[],error_s[], |
| 33 |
warning_s[],lib_tag[][],lib_val[][],block_s[],mc,op,ex,ad,libm,No,EN,LN,FM,MW,MI, |
| 34 |
CAT,JN,CAS,USE,LV,mpfont,atomfont,numberfont,forbiddens,blanks,file_input,file_output; |
| 35 |
pair save_pair[],msize,mposition,fsize,fmargin; |
| 36 |
boolean bA; |
| 37 |
color rgb_black,rgb_gray,rgb_silver,rgb_white,rgb_blue,rgb_navy,rgb_teal,rgb_green,rgb_lime, |
| 38 |
rgb_aqua,rgb_yellow,rgb_red,rgb_fuchsia,rgb_olive,rgb_purple,rgb_maroon; |
| 39 |
%------------------------------------------------------------------------------------------------- |
| 40 |
rgb_black=(0,0,0); rgb_gray=(.5,.5,.5); rgb_silver=(.75,.75,.75); rgb_white=(1,1,1); |
| 41 |
rgb_blue=(0,0,1); rgb_yellow=(1,1,0); rgb_navy=(1,1,0); rgb_teal=(0,.5,.5); |
| 42 |
rgb_green=(0,.5,0); rgb_lime=(0,1,0); rgb_aqua=(0,1,1); rgb_red=(1,0,0); |
| 43 |
rgb_fuchsia=(1,0,1); rgb_olive=(.5,.5,0); rgb_purple=(.5,0,.5); rgb_maroon=(.5,0,0); |
| 44 |
%------------------------------------------------------------------------------------------------- |
| 45 |
fig_num:=str_cnt:=tbl_cnt:=mangle:=sw_frame:=sw_trimming:=sw_ext_all:=sw_omit:=0; |
| 46 |
sw_output:=sw_numbering:=tag_cnt:=pc_all:=MW_n:=f_expand:=0; |
| 47 |
%------------------------------------------------------------------------------------------------- |
| 48 |
libm:="main_lib.mcf"; mpfont:="uhvr8r"; atomfont:=numberfont:="draw"; defaultfont:=mpfont; |
| 49 |
blanks= " "; forbiddens=" &()[]{}^=;!'+,`~"; block_s[0]:=""; |
| 50 |
for s="No","EN","JN","LN","MW","MI","FM","CAT","CAS","USE","LV": tag[incr tag_cnt]:=s; endfor |
| 51 |
Fig=1; Mcode=2; Info=4; Report=8; MOL2k=16; MOL3k=32; Atom=2; Bond=4; All=8; Group=8; Mol=16; |
| 52 |
Outside=1; Inside=2; Bothside:=Outside+Inside; PLS=ASCII("+"); MIS=ASCII("-"); |
| 53 |
%------------------------------------------------------------------------------------------------- |
| 54 |
let DIV= /; let MUL= *; let PADD = ++; let ef=elseif; def ]]]=] ] ] enddef; |
| 55 |
%================================================================================================= |
| 56 |
%--default ahangle=45--------------------------------------------------------------------- |
| 57 |
if ahangle=1: outputformat:="png"; hppp:=vppp:=0.12; % png format(600dpi) |
| 58 |
ef ahangle=2: outputformat:="png"; hppp:=vppp:=0.06; % png format(1200dpi) |
| 59 |
ef ahangle=45: outputformat:="svg"; fi % svg format *default |
| 60 |
%--default ahlength=4--------------------------------------------------------------------- |
| 61 |
if ahlength=3: sw_output:=Fig; f_expand:=1; % output figure(expanded) |
| 62 |
ef ahlength=4: sw_output:=Fig; % output figure *default |
| 63 |
ef ahlength=5: sw_output:=MOL2k; f_expand:=1; % output MOL(V2000) |
| 64 |
ef ahlength=6: sw_output:=MOL3k; f_expand:=1; % output MOL(V3000) |
| 65 |
ef ahlength=7: sw_output:=Report; fi % output report |
| 66 |
%-- default bboxmargin=2------------------------------------------------------------------ |
| 67 |
if bboxmargin=3: ext(defaultfont:=mpfont; defaultscale:=.3; label.rt(EN,(0,0));) |
| 68 |
ef bboxmargin=4: sw_output:=Fig+Report; |
| 69 |
ext(defaultfont:=mpfont; defaultscale:=.3; |
| 70 |
label.rt(EN&" / "&MW&" / "&decimal(MW_n-scantokens(MW)),(0,0));) fi |
| 71 |
%--default outputtemplate:="%j-%3c."&"svg"------------------------------------------------ |
| 72 |
if outputformat="svg": outputtemplate:="%3c-%{EN_}.svg"; |
| 73 |
ef outputformat="png": if hppp=0.12: outputtemplate:="p06_%3c-%{EN_}.png"; |
| 74 |
ef hppp=0.06: outputtemplate:="p12_%3c-%{EN_}.png"; fi fi |
| 75 |
%----------------------------------------------------------------------------------------- |
| 76 |
message "* jobname="&jobname; |
| 77 |
message "* numbersystem="&numbersystem; |
| 78 |
message "* outputformat="&outputformat; |
| 79 |
message "* outputtemplate="&outputtemplate; |
| 80 |
clearit; |
| 81 |
%------------------------------------------------------------------------------------------------- |
| 82 |
ratio_chain_ring:=0.66; ratio_atom_bond:=0.36; ratio_thickness_bond:=0.012; ratio_char_atom:=0.12; |
| 83 |
ratio_bondgap_bond:=0.15; ratio_hashgap_bond:=0.12; ratio_hash_black:=0.4; ratio_wedge_bond:=0.12; |
| 84 |
ratio_atomgap_atom:=0.05; offset_thickness:=0.25; offset_bond_gap:=0.3; offset_hash_gap:=0.1; |
| 85 |
offset_atom:=0.8; offset_wedge:=0.2; thickness_frame:=0.2; |
| 86 |
max_blength:=10mm; blength:=mangle:=0; max_labelsize:=20mm; dottedline_gap:=1.5; |
| 87 |
fsize:=(30mm,20mm); fmargin:=(0.4mm,0.4mm); msize:=(1,1); mposition:=(0.5,0.5); |
| 88 |
ahangle:=45; ahlength:=4; defaultsize:=8; defaultscale:=1; labeloffset:=3; ext_defaultline:=0.5; |
| 89 |
lonepairdiam:=lonepairspace:=circlediam:=circlepen:=bboxmargin:=0; mc_length:=100; |
| 90 |
%------------------------------------------------------------------------------------------------- |
| 91 |
def ext(text t)= sw_ext_all:=1; def EXT_ALL = t enddef; enddef; |
| 92 |
def ext_clear= sw_ext_all:=0; def EXT_ALL = enddef; enddef; |
| 93 |
def wpcs expr n= withpen pencircle scaled n enddef; |
| 94 |
def ppcs expr n= pickup pencircle scaled n enddef; |
| 95 |
def sbp(expr m,n)expr p=subpath(m*length p,n*length p) of p enddef; |
| 96 |
def puts expr s= write s to file_output enddef; |
| 97 |
%------------------------------------------------------------------------------------------------- |
| 98 |
vardef iif(expr a,b,c)=if a: b else: c fi enddef; |
| 99 |
vardef sfrt(expr a,b,c)= a shifted ((b,0) rotated c) enddef; |
| 100 |
vardef fsr(expr n)(expr s)= (substring(0,n-length s) of blanks)&s enddef; |
| 101 |
vardef fsl(expr n)(expr s)= s&(substring(0,n-length s) of blanks) enddef; |
| 102 |
vardef fdr(expr n)(expr s)= |
| 103 |
if length(decimal s)>n: substring (0,n) of decimal s else: fsr(n)(decimal s) fi enddef; |
| 104 |
vardef fdl(expr n)(expr s)= fsl(n)(decimal s) enddef; |
| 105 |
vardef subc(expr s,n)= substring(n-1,n) of s enddef; |
| 106 |
%================================================================================================= |
| 107 |
pc_emb_start=1001; % 1001 => 1900 for embedded pcode (max 900) |
| 108 |
pc_emi_start=1901; % 1901 => 2000 for embedded internal pcode (max 100) |
| 109 |
pc_usr_start=2001; % 2001 => 3000 for user pcode (max 1000) |
| 110 |
pc_int_start=3000; % 3001 => 4000 for internal pcode (max 1000) |
| 111 |
%------------------------------------------------------------------------------------------------- |
| 112 |
def def_com(expr n)(text tx)= nA:=n; forsuffixes $=tx: $=nA; nA:=nA+1; endfor enddef; |
| 113 |
def_com(-4090)(_com,_jp_atom,_jp_absA,_jp_bond,_cyc,_cyc_sB,_cyc_eB,_set_line,_tmp_line,_tmp_rot, |
| 114 |
_tmp_env,_tmp_len,_chg_len,_get_len,_set_len,_rot_ang,_adj_ang,_chg_env,_set_colorA,_set_colorB, |
| 115 |
_grp_si,_grp_dm,_grp_wf,_grp_zf,_set_adrA,_set_adrB,_mk_bond,_set_atom,_auto_ang, |
| 116 |
_set_charge,_add_charge,_chg_atom,_fuse,_fuse_ext,_size_atom,_adr,_numeric_rot,_jump_at, |
| 117 |
_nop,_mark,_moff,_term,_end,_grp_s,_grp_e,_rest,_ring,_chain, |
| 118 |
hz,vt,lr,rl,ll,rr,si,dl,dl_,dr,dr_,db,dm,dm_,tm,wf,wb,bd,bz,zf,zb,dt,wv,nl,vf,vb,no, |
| 119 |
wf_r,wb_r,bd_r,arc_lb,arc_br,arc_lbr,arc_ltr,si_,wf_,wb_,zf_,zb_,wv_,bd_); |
| 120 |
%------------------------------------------------------------------------------------------------- |
| 121 |
def parameter_list= |
| 122 |
sw_numbering,sw_output,sw_ext_all,sw_frame,sw_trimming,sw_omit,ratio_atom_bond, |
| 123 |
ratio_thickness_bond,ratio_chain_ring,ratio_bondgap_bond,ratio_hash_black,ratio_hashgap_bond, |
| 124 |
ratio_wedge_bond,ratio_atomgap_atom,ratio_char_atom,offset_atom,offset_wedge,max_blength, |
| 125 |
offset_hash_gap,offset_bond_gap,thickness_frame,offset_thickness,defaultsize,defaultscale, |
| 126 |
labeloffset,mangle,blength,fsize,fmargin,msize,mposition,defaultfont,atomfont,dottedline_gap |
| 127 |
enddef; |
| 128 |
%------------------------------------------------------------------------------------------------- |
| 129 |
def store_restore_par(expr n)(text t)= |
| 130 |
nA:=nB:=nC:=0; |
| 131 |
if n=0: for $=t: if numeric $: save_num[incr nA]:=$; ef pair $: save_pair[incr nB]:=$; |
| 132 |
ef string $: save_str[incr nC]:=$; fi endfor |
| 133 |
ef n=1: for $=t: if numeric $: if save_num[incr nA]<>$: save_num[nA]:=$; fi |
| 134 |
ef pair $: if save_pair[incr nB]<>$: save_pair[nB]:=$; fi |
| 135 |
ef string $: if save_str[incr nC]<>$: save_str[nC]:=$; fi fi endfor |
| 136 |
ef n=2: forsuffixes $=t: if numeric $: if $<>save_num[incr nA]: $:=save_num[nA]; fi |
| 137 |
ef pair $: if $<>save_pair[incr nB]: $:=save_pair[nB]; fi |
| 138 |
ef string $: if $<>save_str[incr nC]: $:=save_str[nC]; fi fi endfor |
| 139 |
fi |
| 140 |
enddef; |
| 141 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 142 |
def beginfigm= |
| 143 |
begingroup |
| 144 |
save ','',`,``,@,#,#@,##,|=,|<,**,++,f_ext,blen,ext,add,ang_br,fw_n,bw_n,at_cmm,bond_cntA, |
| 145 |
warning_cnt,hideH,hideH_cnt,cntM,cntA,cntB,minX,minY,maxX,maxY,posA,posM,lineB, |
| 146 |
sB,eB,angB,angA,lenB,angX,numS,sumA,bond_num,wdM,htM,chargeA,addA,add_rot,mol_pic,color_list, |
| 147 |
mw,mi,fm,grp_num,f_type,ay,bx,by,pcnt; |
| 148 |
numeric hideH[],lineB[],sB[],eB[],angB[],angA[],lenB[],angX[],strA[],sumA[],bond_num[], |
| 149 |
wdM[],htM[],chargeA[],addA[],add_rot[]; |
| 150 |
pair posA[],posM[][]; |
| 151 |
string mi,fm,mw; |
| 152 |
picture mol_pic[]; |
| 153 |
color color_list[]; |
| 154 |
%----------------------------------------------------------------------------------------------- |
| 155 |
store_restore_par(1)(parameter_list); |
| 156 |
mc:=ex:=ad:=op:=mw:=mi:=fm:=""; No:=EN:=JN:=LN:=MW:=FM:=MI:=CAS:=CAT:=LV:=USE:="-"; |
| 157 |
f_ext:=cntM:=mc_row:=ex_row:=ad_row:=op_row:=param_int:=warning_cnt:=error_cnt:=0; |
| 158 |
let ext=ext_to_fig; let add=add_to_molecule; let ++=add_to_molecule; let **=ext_to_fig; |
| 159 |
def ' = define_parts enddef; def `(expr s)=define_grp_string(s)() enddef; |
| 160 |
def `` = define_grp_string enddef; def @ expr p= mposition:=p; enddef; |
| 161 |
def # expr p= fsize:=p; enddef; def #@ expr p=fmargin:=p; enddef; |
| 162 |
def ## expr p = msize:=p; enddef; |
| 163 |
def |=(expr n) = blength:=n; enddef; def |<(expr n) = max_blength:=n; enddef; |
| 164 |
pc_num:=pc_usr_start; pc_int:=pc_int_start; fig_num:=fig_num+1; |
| 165 |
mol_pic[0]:=nullpicture; |
| 166 |
enddef; |
| 167 |
%------------------------------------------------------------------------------------------------- |
| 168 |
def endfigm= |
| 169 |
if cntM>=1: |
| 170 |
if scan_bit(sw_output,Fig): |
| 171 |
if EN<>"-": EN_:=forbidden_to_underbar(EN); else: EN_:="no_name"; fi |
| 172 |
beginfig(fig_num) |
| 173 |
if sw_ext_all=1: ext_to_fig(EXT_ALL); fi |
| 174 |
if sw_trimming>=1: |
| 175 |
nA:=nC:=4095; nB:=nD:=-4095; |
| 176 |
for i=1 upto cntM: if xpart posM[1][i]<nA: nA:=xpart posM[1][i]; fi |
| 177 |
if xpart posM[2][i]>nB: nB:=xpart posM[2][i]; fi |
| 178 |
if ypart posM[1][i]<nC: nC:=ypart posM[1][i]; fi |
| 179 |
if ypart posM[2][i]>nD: nD:=ypart posM[2][i]; fi |
| 180 |
endfor |
| 181 |
fig_wd:=nB-nA+2xpart fmargin; fig_ht:=nD-nC+2ypart fmargin; fsize:=(fig_wd,fig_ht); |
| 182 |
for i=1 upto cntM: |
| 183 |
posM[0][i]:=posM[0][i]+fmargin-(nA,nC); posM[1][i]:=posM[1][i]+fmargin-(nA,nC); |
| 184 |
endfor |
| 185 |
fi |
| 186 |
if scan_bit(sw_frame,Outside): draw_frame((0,0),fsize,thickness_frame); |
| 187 |
else: draw_corner(fsize,0.004); fi |
| 188 |
if scan_bit(sw_frame,Inside): draw_frame(fmargin,fsize-2fmargin,thickness_frame); fi |
| 189 |
for i=1 upto cntM: |
| 190 |
addto currentpicture also mol_pic[i] shifted posM[0][i]; mol_pic[i]:=nullpicture; |
| 191 |
if scan_bit(sw_frame,Mol): ext(draw_frame(p[i],(w[i],h[i]),thickness_frame)) fi |
| 192 |
endfor |
| 193 |
if f_ext=1: addto currentpicture also mol_pic[0]; mol_pic[0]:=nullpicture; fi |
| 194 |
endfig; |
| 195 |
clearit; |
| 196 |
fi |
| 197 |
ef scan_bit(sw_output,Fig): |
| 198 |
if EN<>"-": EN_:=forbidden_to_underbar(EN); else: EN_:="no_name"; fi |
| 199 |
beginfig(fig_num) |
| 200 |
defaultscale:=.6; draw_frame((0,0),fsize,thickness_frame) label("no figure",0.5fsize); |
| 201 |
endfig; |
| 202 |
clearit; |
| 203 |
fi |
| 204 |
if scan_bit(sw_output,Mcode): proc_mc_out; fi |
| 205 |
if scan_bit(sw_output,Report): proc_report_out; fi |
| 206 |
if scan_bit(sw_output,MOL2k): proc_mol_out(2000); fi |
| 207 |
if scan_bit(sw_output,MOL3k): proc_mol_out(3000); fi |
| 208 |
store_restore_par(2)(parameter_list); |
| 209 |
message "["&decimal fig_num&"]EN:"&EN; message ""; |
| 210 |
endgroup; % [;] |
| 211 |
enddef; |
| 212 |
%================================================================================================= |
| 213 |
def readm(text t)= for $=t: mc[incr mc_row]:=$; mc:=mc&mc[mc_row]; endfor enddef; |
| 214 |
def getm(expr a)= if string a: read_unit(get_adr("EN",a)) ef numeric a: read_unit(a) fi enddef; |
| 215 |
%------------------------------------------------------------------------------------------------- |
| 216 |
def read_unit(expr n)= |
| 217 |
f_line:=0; |
| 218 |
if (n>=1)and(n<=ucount): |
| 219 |
for i=1 upto unit_info[n]: |
| 220 |
for j=1 upto tag_cnt: if lib_tag[n][i]=tag[j]: scantokens(tag[j]):=lib_val[n][i]; fi endfor |
| 221 |
endfor |
| 222 |
for i=1 upto unit_lines[n]: |
| 223 |
lines:=row[n][i]; tempc:=substring (0,1) of lines; exitif tempc=";"; |
| 224 |
if tempc=":": f_line:=1; ef tempc="=": f_line:=2; ef tempc="*": f_line:=3; |
| 225 |
ef tempc="+": f_line:=4; ef tempc="%": |
| 226 |
else: nA:=0; len_s:=length lines; |
| 227 |
for j=1 upto len_s: if subc(lines,j)<>" ": nA:=j; fi exitif nA>0; endfor |
| 228 |
fw_n:=nA-1; temps:=substring(fw_n,len_s) of lines; |
| 229 |
if f_line=1: mc_indent[incr mc_row]:=fw_n; mc[mc_row]:=temps; mc:=mc&temps; |
| 230 |
ef f_line=2: op[incr op_row]:=temps; op:=op&temps; |
| 231 |
ef f_line=3: ex[incr ex_row]:=temps; ex:=ex&temps; |
| 232 |
ef f_line=4: ad[incr ad_row]:=temps; ad:=ad&temps; fi fi |
| 233 |
endfor |
| 234 |
fi |
| 235 |
enddef; |
| 236 |
%------------------------------------------------------------------------------------------------- |
| 237 |
vardef get_adr(expr t,v)= |
| 238 |
save adr_n; adr_n:=0; |
| 239 |
for i=1 upto ucount: for j=1 upto unit_info[i]: |
| 240 |
if (lib_tag[i][j]=t)and(lib_val[i][j]=v): adr_n:=i; fi exitif adr_n>=1; |
| 241 |
endfor endfor adr_n |
| 242 |
enddef; |
| 243 |
%------------------------------------------------------------------------------------------------- |
| 244 |
def putm= if op_row>=1: scantokens(op) fi |
| 245 |
if mc_row>=1: drawm(mc) fi |
| 246 |
if ad_row>=1: add(scantokens(ad)) fi |
| 247 |
if ex_row>=1: ext(scantokens(ex)) fi enddef; |
| 248 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 249 |
vardef pc_extend(expr p,a,b,c)= |
| 250 |
param_e[incr param_int][1]:=a; param_e[param_int][2]:=b; param_e[param_int][3]:=c; (p,param_int) |
| 251 |
enddef; |
| 252 |
%------------------------------------------------------------------------------------------------- |
| 253 |
error_s[1]="*Invalid adrA "; error_s[2]="*Invalid adrB "; error_s[3]="*Unknown found "; |
| 254 |
error_s[4]="*Forbidden char "; error_s[5]="*Not match ( ) "; error_s[6]="*Blank block "; |
| 255 |
error_s[7]="*Unknown after &@"; error_s[8]="*Unknown after = "; |
| 256 |
def message_error(expr n,e) = |
| 257 |
error_b[incr error_cnt]:=n; error_e[error_cnt]:=e; |
| 258 |
message "["&decimal fig_num&"]"&error_s[e]&" <"&decimal n&"> "&block_s[n]; message ""; enddef; |
| 259 |
%------------------------------------------------------------------------------------------------- |
| 260 |
vardef $# primary n = if numeric n: n-4095 else: _nop fi enddef; |
| 261 |
vardef *\ primary n = if numeric n: n+0.1 else: _nop fi enddef; |
| 262 |
primarydef a _ b = a for i=a+1 upto b: 'i endfor enddef; |
| 263 |
primarydef a--+b = pc_extend(_fuse_ext,a,b,2) enddef; |
| 264 |
primarydef a---b = pc_extend(_fuse_ext,a,b,3) enddef; |
| 265 |
primarydef a----b = pc_extend(_fuse_ext,a,b,4) enddef; |
| 266 |
primarydef a&&b = if (known a)and(known b): add_parts(a,b) else: _nop fi enddef; |
| 267 |
tertiarydef a==b = if (known a)and(known b): set_bond(a,b) else: _nop fi enddef; |
| 268 |
tertiarydef a:|b = if (known a)and(known b): set_atom(a,b) else: _nop fi enddef; |
| 269 |
tertiarydef a^^b= (_tmp_rot,b),a enddef; |
| 270 |
tertiarydef a~~b= (_tmp_line,b),a enddef; |
| 271 |
tertiarydef a'`b= (_tmp_len,b),a enddef; |
| 272 |
tertiarydef a<<b= if numeric a: if (a>=!2)and(a<=!20): b for i=0 upto a-!2:,b endfor |
| 273 |
else: (_tmp_env,b),a fi else: (_tmp_env,b),a fi enddef; |
| 274 |
%----------------------------------------------------------------------------------------------- |
| 275 |
def @@(expr n)=^~$0,angle(pc_y[n][1],pc_y[n][2])~no`length(pc_y[n][1],pc_y[n][2]),^~$0 enddef; |
| 276 |
def @@$ secondary n = if numeric n: :> $1,@@(n) else: _nop fi enddef; |
| 277 |
def `' primary n = if numeric n: (_chg_len,n) else: _nop fi enddef; |
| 278 |
def ^~ primary n = if numeric n: (_rot_ang,n) else: _nop fi enddef; |
| 279 |
def <: primary n = if numeric n: (_cyc,n) else: _nop fi enddef; |
| 280 |
def :> primary n = if numeric n: (_jp_atom,n) else: _nop fi enddef; |
| 281 |
def /\ secondary n = if numeric n: (_grp_si,n) else: _nop fi enddef; |
| 282 |
def // secondary n = if numeric n: (_grp_dm,n) else: _nop fi enddef; |
| 283 |
def */ secondary n = if numeric n: (_grp_wf,n) else: _nop fi enddef; |
| 284 |
def /* secondary n = if numeric n: (_grp_zf,n) else: _nop fi enddef; |
| 285 |
def */* secondary n = if numeric n: /n~~wv else: _nop fi enddef; |
| 286 |
%------------------------------------------------------------------------------------------------- |
| 287 |
def CP(expr x,y)= pc_x[pc_int][incr pc_cnt[pc_int]]:=x; pc_y[pc_int][pc_cnt[pc_int]]:=y; enddef; |
| 288 |
def DL(expr p)=CP(_set_adrB,p) CP(_set_line,dl) enddef; |
| 289 |
def MB(expr p)=CP(_mk_bond,p) enddef; |
| 290 |
def CC(expr p)=CP(_com,p) enddef; |
| 291 |
def CA(expr x,y,n)= pc_add_adress(x,y,n,_set_adrA) enddef; |
| 292 |
def CB(expr x,y,n)= pc_add_adress(x,y,n,_set_adrB) enddef; |
| 293 |
def pc_add_adress(expr x,y,n,c)= |
| 294 |
if n>=pc_emb_start: for i=1 upto pc_cnt[n]: if pc_x[n][i]=_adr: CP(c,pc_y[n][i]) CP(x,y) |
| 295 |
else: CP(pc_x[n][i],pc_y[n][i]) fi endfor |
| 296 |
else: CP(c,n) CP(x,y) fi |
| 297 |
enddef; |
| 298 |
%------------------------------------------------------------------------------------------------- |
| 299 |
def redefine_tokens= |
| 300 |
save ',~,`,^,--,/,*,$,n,p; let '=&&; let ~=~~; let `='`; let ^=^^; let -- = --+; let /=/\; |
| 301 |
def *=*\ enddef; def $=$# enddef; def n=n_ enddef; def p=p_ enddef; |
| 302 |
enddef; |
| 303 |
%================================================================================================= |
| 304 |
def read_mcf_string(expr s)= |
| 305 |
begingroup |
| 306 |
save len_s,at_eqcl,at_prs,at_quot,at_temp,f_temp,eqcl_cnt,f_binop,f_eqcl,pre_c; |
| 307 |
numeric at_eqcl[],at_prs[],at_quot[],f_binop[],f_eqcl[]; |
| 308 |
string pre_c; |
| 309 |
block_cnt:=split_str(s,",")(block_s); block_s[incr block_cnt]:="(_com,_term)"; |
| 310 |
%------------------------------------------------------------------------------ |
| 311 |
for i=1 upto block_cnt-1: |
| 312 |
temps:=erase_blank block_s[i]; len_s:=length temps; tempc:=substring (0,1) of temps; |
| 313 |
if temps="": message_error(i,6); temps:=""; |
| 314 |
ef is_char("@#\&{}[]%;|"&ditto,temps)>0: message_error(i,4); temps:=""; |
| 315 |
ef match_paren(temps)<>0: message_error(i,5); temps:=""; |
| 316 |
ef temps="`": temps:="=|"; |
| 317 |
ef temps="<": temps:="|>"; |
| 318 |
ef temps=">": temps:="<|"; |
| 319 |
ef tempc="^": temps:="^~"&substring(1,len_s) of temps; |
| 320 |
ef tempc=":": temps:="<:"&substring(1,len_s) of temps; |
| 321 |
ef tempc="`": temps:="`'"&substring(1,len_s) of temps; |
| 322 |
ef substring (len_s-1,len_s) of temps=":": |
| 323 |
if subc(temps,len_s-1)=")": temps:="@@"&substring(0,len_s-1) of temps; |
| 324 |
else: temps:=":>"&substring(0,len_s-1) of temps; fi |
| 325 |
else: |
| 326 |
if is_char("=:^`",temps)>0: |
| 327 |
eqcl_cnt:=quot_cnt:=at_temp:=f_temp:=f_prs:=0; |
| 328 |
if (tempc="/")or((tempc="*")and(subc(temps,2)="/")): f_temp:=1; fi |
| 329 |
for j=1 upto len_s: |
| 330 |
tempc:=subc(temps,j); |
| 331 |
if tempc="'": at_quot[incr quot_cnt]:=j; f_eqcl[quot_cnt]:=0; |
| 332 |
ef tempc="(": f_temp:=0; |
| 333 |
ef (tempc=":")or(tempc="="): if f_temp=1: f_eqcl[quot_cnt]:=f_prs:=1; fi f_temp:=1; fi |
| 334 |
endfor |
| 335 |
at_quot[quot_cnt+1]:=len_s+1; f_temp:=0; |
| 336 |
if f_prs=1: for j=quot_cnt downto 1: |
| 337 |
if f_eqcl[j]=1: temps:=substring(0,at_quot[j])of temps&"("& |
| 338 |
substring(at_quot[j],at_quot[j+1]-1)of temps&")"& |
| 339 |
substring(at_quot[j+1]-1,length temps)of temps; fi |
| 340 |
endfor fi |
| 341 |
for j=1 upto length temps: |
| 342 |
tempc:=subc(temps,j); |
| 343 |
if (tempc="^")or(tempc="`")or(tempc="~")or(tempc="_")or |
| 344 |
((tempc="-")and(subc(temps,j+1)="-")): f_temp:=1; |
| 345 |
ef tempc="(": at_temp:=j; f_temp:=0; |
| 346 |
ef (tempc=":")or(tempc="="): |
| 347 |
at_eqcl[incr eqcl_cnt]:=j; at_prs[eqcl_cnt]:=at_temp; f_binop[eqcl_cnt]:=f_temp; fi |
| 348 |
endfor |
| 349 |
for j=eqcl_cnt downto 1: |
| 350 |
if f_binop[j]>0: |
| 351 |
temps:=substring(0,at_prs[j]) of temps&"&@("& |
| 352 |
substring(at_prs[j],at_eqcl[j]-1) of temps&")"& |
| 353 |
substring(at_eqcl[j]-1,length temps) of temps; fi |
| 354 |
endfor |
| 355 |
ts:=temps; |
| 356 |
for j=length ts downto 1: |
| 357 |
if subc(ts,j)="^": tempc:=subc(ts,j+1); |
| 358 |
if ((tempc>="0")and(tempc<="9"))or(tempc="-")or(tempc=".")or(tempc="$"): |
| 359 |
ef tempc="*": ts:=substring(0,j-1)of ts&"<<"&substring(j+1,4095)of ts; |
| 360 |
else: ts:=substring(0,j-1)of ts&"<<"&substring(j,4095)of ts; fi |
| 361 |
ef subc(ts,j)="`": tempc:=subc(ts,j-1); |
| 362 |
if (tempc="=")or(tempc="/")or(tempc="*"): |
| 363 |
ts:=substring(0,j-1)of ts&"`'"&substring(j,4095)of ts; fi |
| 364 |
ef subc(ts,j)=":": ts:=substring(0,j-1)of ts&":|"&substring(j,4095)of ts; |
| 365 |
ef subc(ts,j)="=": ts:=substring(0,j-1)of ts&"=="&substring(j,4095)of ts; fi |
| 366 |
endfor |
| 367 |
if temps<>ts: temps:=ts; fi |
| 368 |
fi |
| 369 |
fi |
| 370 |
block_s[i]:=temps; |
| 371 |
endfor |
| 372 |
%----------------------------------------------------------------------------------- |
| 373 |
redefine_tokens; |
| 374 |
mc_cnt:=0; |
| 375 |
for i=1 upto block_cnt: |
| 376 |
for $=scantokens(block_s[i]): |
| 377 |
if known $: |
| 378 |
if numeric $: if $>=pc_emb_start: expand_pcode($,i); |
| 379 |
ef $=_nop: message_error(i,3); |
| 380 |
else: mc_x[incr mc_cnt]:=_mk_bond; mc_y[mc_cnt]:=$; mc_b[mc_cnt]:=i; fi |
| 381 |
ef pair $: mc_x[incr mc_cnt]:=xpart $; mc_y[mc_cnt]:=ypart $; mc_b[mc_cnt]:=i; fi |
| 382 |
else: message_error(i,3); fi |
| 383 |
endfor |
| 384 |
endfor |
| 385 |
endgroup |
| 386 |
enddef; |
| 387 |
%------------------------------------------------------------------------------------------------- |
| 388 |
vardef define_parts(text t)= |
| 389 |
pc_cnt[incr pc_num]:=0; |
| 390 |
redefine_tokens; |
| 391 |
for $=t: if known $: if pair $: pc_x[pc_num][incr pc_cnt[pc_num]]:=xpart $; |
| 392 |
pc_y[pc_num][pc_cnt[pc_num]]:=ypart $; |
| 393 |
ef numeric $: if $>=pc_emb_start: pc_x[pc_num][incr pc_cnt[pc_num]]:=$; |
| 394 |
else: pc_x[pc_num][incr pc_cnt[pc_num]]:=_mk_bond; |
| 395 |
pc_y[pc_num][pc_cnt[pc_num]]:=$; fi fi fi |
| 396 |
endfor pc_num |
| 397 |
enddef; |
| 398 |
%------------------------------------------------------------------------------------------------- |
| 399 |
def expand_pcode(expr a,b)= |
| 400 |
for i=1 upto pc_cnt[a]: |
| 401 |
if pc_x[a][i]>=pc_emb_start: expand_pcode(pc_x[a][i],b); |
| 402 |
else: mc_x[incr mc_cnt]:=pc_x[a][i]; mc_y[mc_cnt]:=pc_y[a][i]; mc_b[mc_cnt]:=b; fi |
| 403 |
endfor |
| 404 |
enddef; |
| 405 |
%------------------------------------------------------------------------------------------------- |
| 406 |
vardef &@(text t)= |
| 407 |
save '; let ' = , ; pc_int:=pc_int+1; pcnt:=0; |
| 408 |
for $=t: |
| 409 |
if known $: if numeric $: pc_x[pc_int][incr pcnt]:=_adr; pc_y[pc_int][pcnt]:=$; |
| 410 |
ef pair $: pc_x[pc_int][incr pcnt]:=xpart $; pc_y[pc_int][pcnt]:=ypart $; fi |
| 411 |
else: message_error(0,7); fi |
| 412 |
endfor |
| 413 |
pc_cnt[pc_int]:=pcnt; pc_int |
| 414 |
enddef; |
| 415 |
%------------------------------------------------------------------------------------------------- |
| 416 |
vardef add_parts(expr a,b)= |
| 417 |
if pair a: pc_x[incr pc_int][1]:=xpart a; pc_y[pc_int][1]:=ypart a; pc_x[pc_int][2]:=b; |
| 418 |
pc_cnt[pc_int]:=2; |
| 419 |
ef (a<pc_emb_start)and(b<pc_emb_start): |
| 420 |
pc_x[incr pc_int][1]:=_adr; pc_x[pc_int][2]:=_adr; pc_y[pc_int][1]:=a; pc_y[pc_int][2]:=b; |
| 421 |
pc_cnt[pc_int]:=2; |
| 422 |
ef (a>=pc_int_start)and(b<pc_int_start): |
| 423 |
if b<pc_emb_start: pc_x[a][incr pc_cnt[a]]:=_adr; pc_y[a][pc_cnt[a]]:=b; |
| 424 |
else: pc_x[a][incr pc_cnt[a]]:=b; fi |
| 425 |
else: pc_x[incr pc_int][1]:=a; pc_x[pc_int][2]:=b; pc_cnt[pc_int]:=2; fi |
| 426 |
pc_int |
| 427 |
enddef; |
| 428 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 429 |
def fuse_ring(expr a,b) = |
| 430 |
CP(_jp_bond,a) CP(_rot_ang,180) CP(_get_len,a) for i=3 upto b: MB(360 DIV b) endfor |
| 431 |
CP(_set_len,_end) if a<=0: CP(_cyc_eB,a-b+2) else: CP(_cyc_eB,a) fi |
| 432 |
enddef; |
| 433 |
def fuse_ring_bonds(expr s,e,b,c) = |
| 434 |
CP(_jp_bond,s) CP(_rot_ang,180) |
| 435 |
if b=6: CP(_set_len,1) for i=2 upto c: MB(60) endfor |
| 436 |
ef b=5: if c=2: CP(_set_len,1.25) MB(80) ef c=3: CP(_set_len,1.1) MB(78) MB(72) fi |
| 437 |
ef b=4: CP(_set_len,1.225) MB(105) fi |
| 438 |
CP(_set_len,_end) if e<=0: CP(_cyc_eB,e-c+1) else: CP(_cyc_eB,e) fi |
| 439 |
enddef; |
| 440 |
def fuse_ring_size(expr a,b,c) = |
| 441 |
CP(_jp_bond,a) CP(_rot_ang,180) CP(_set_len,c) |
| 442 |
if b=5: MB(72-((10c-9) MUL 1.5)) MB(63+10c) MB(63+10c) |
| 443 |
ef b=6: MB(68-10c) for i=1 upto 3: MB(60+(5c-4)) endfor fi |
| 444 |
CP(_set_len,_end) if a<=0: CP(_cyc_eB,a-b+2) else: CP(_cyc_eB,a) fi |
| 445 |
enddef; |
| 446 |
%================================================================================================= |
| 447 |
vardef set_bond(expr a,b) = |
| 448 |
pc_cnt[incr pc_int]:=0; |
| 449 |
if numeric b: |
| 450 |
if (b>=si)and(b<=bd_): |
| 451 |
if a>=pc_int_start: |
| 452 |
for i=1 upto pc_cnt[a]: if pc_x[a][i]=_adr: CP(_set_adrB,pc_y[a][i]) CP(_set_line,b) fi |
| 453 |
endfor |
| 454 |
else: CP(_set_adrB,a) CP(_set_line,b) fi |
| 455 |
ef (b>=?3)and(b<=Ph2)or(b>=pc_int_start): |
| 456 |
if numeric a: |
| 457 |
if a>=pc_int_start: |
| 458 |
for i=1 upto pc_cnt[a]: |
| 459 |
ay:=pc_y[a][i]; |
| 460 |
if pc_x[a][i]=_adr: if b=Ph1: fuse_ring(ay,6) DL(-2) DL(-4) |
| 461 |
ef b=Ph2: fuse_ring(ay,6) DL(-1) DL(-3) DL(-5) |
| 462 |
else: fuse_ring(ay,b-?3+3) fi |
| 463 |
ef pc_x[a][i]=_fuse_ext: |
| 464 |
fuse_ring_bonds(param_e[ay][1],param_e[ay][2],b-?4+4,b-?4+4-param_e[ay][3]) fi |
| 465 |
endfor |
| 466 |
else: if b=Ph1: fuse_ring(a,6) DL(-2) DL(-4) |
| 467 |
ef b=Ph2: fuse_ring(a,6) DL(-1) DL(-3) DL(-5) |
| 468 |
ef b>=pc_int_start: if (pc_x[b][1]=_chg_len)and(pc_x[b][2]>=?5)and(pc_x[b][2]<=?6): |
| 469 |
fuse_ring_size(a,pc_x[b][2]-?3+3,pc_y[b][1]) fi |
| 470 |
else: fuse_ring(a,b-?3+3) fi |
| 471 |
fi |
| 472 |
ef pair a: |
| 473 |
if xpart a=_fuse_ext: |
| 474 |
ay:=ypart a; fuse_ring_bonds(param_e[ay][1],param_e[ay][2],b-?4+4,b-?4+4-param_e[ay][3]) |
| 475 |
fi |
| 476 |
fi |
| 477 |
else: message_error(0,8); |
| 478 |
fi |
| 479 |
ef color b: cntC:=cntC+1; color_list[cntC]:=b; CB(_set_colorB,cntC,a) fi |
| 480 |
pc_int |
| 481 |
enddef; |
| 482 |
%------------------------------------------------------------------------------------------------- |
| 483 |
vardef set_atom(expr a,b)= |
| 484 |
pc_cnt[incr pc_int]:=pcnt:=f_type:=0; |
| 485 |
if numeric b: if (b>=?)and(b<=?dm): bx:=pc_x[b][1]; by:=pc_y[b][1]; f_type:=1; fi |
| 486 |
ef pair b: bx:=xpart b; by:=ypart b; f_type:=1; |
| 487 |
ef color b: f_type:=2; fi |
| 488 |
if f_type=0: if (b>pc_emb_start)and(b<=pc_atm_end): CA(_chg_atom,b,a) |
| 489 |
ef b=NH: CA(_chg_atom,N,a) if f_expand=0: CP(_tmp_line,nl) fi |
| 490 |
CC(_grp_s) CA(_grp_si,H,a) CC(_grp_e) |
| 491 |
ef b=N?: CA(_chg_atom,N,a) CC(_grp_s) CA(_grp_si,NO_ATOM,a) CC(_grp_e) |
| 492 |
ef b=N?2: CA(_chg_atom,N,a) CC(_grp_s) CA(_grp_si,!,a) CC(_grp_e) |
| 493 |
ef b=??: CP(_tmp_rot, 35) CC(_grp_s) CA(_grp_si,NO_ATOM,a) CC(_grp_e) |
| 494 |
CP(_tmp_rot,-35) CC(_grp_s) CA(_grp_si,NO_ATOM,a) CC(_grp_e) |
| 495 |
ef b=n_: CC(_grp_s) CA(_set_charge,MIS,a) CC(_grp_e) |
| 496 |
ef b=p_: CC(_grp_s) CA(_set_charge,PLS,a) CC(_grp_e) fi |
| 497 |
ef f_type=1: CC(_grp_s) CA(bx,by,a) CC(_grp_e) |
| 498 |
ef f_type=2: cntC:=cntC+1; color_list[cntC]:=b; CA(_set_colorA,cntC,a) fi |
| 499 |
pc_cnt[pc_int]:=pc_cnt[pc_int]; pc_int |
| 500 |
enddef; |
| 501 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 502 |
def ext_setup= |
| 503 |
pickup pencircle scaled ext_defaultline; |
| 504 |
dotlabeldiam:=3; labeloffset:=3; em:=defaultscale*defaultsize; defaultfont:=mpfont; |
| 505 |
let # = scaled; let << = rotated; let => = shifted; __ = (1,0); An:=cntA; Bn:=cntB; |
| 506 |
primarydef a /* b = point b of a enddef; |
| 507 |
enddef; |
| 508 |
%------------------------------------------------------------------------------------------------- |
| 509 |
def add_to_molecule(text t)= |
| 510 |
begingroup |
| 511 |
save w,h,n,l,p,am,aw,A,B,An,Bn,plus,minus,lonepair,__,#,=>,<<,/*; |
| 512 |
numeric A[]dir,B[]up,A[]ang,B[]ang; |
| 513 |
pair __,p[],A[],B[]s,B[]e,B[]m,A[]up,A[]left,A[]right,A[]down,B[]up,B[]left,B[]right,B[]down; |
| 514 |
path B[]; |
| 515 |
def plus = circled_plus_add enddef; def minus = circled_minus_add enddef; |
| 516 |
def lonepair = lone_pair_add enddef; |
| 517 |
ext_setup; |
| 518 |
w:=mol_wd; h:=mol_ht; l:=blen; aw:=atom_wd; p0:=(minX,minY); |
| 519 |
lonepairdiam:=0.3aw; lonepairspace:=.7aw; circlediam:=.6aw; circlepen:=.2; |
| 520 |
for i=1 upto cntA: |
| 521 |
A[i]:=posA[i]; A[i]ang:=angX[i]; A[i]up:=dir(angX[i]); |
| 522 |
A[i]left:=dir(angX[i]+90); A[i]right:=dir(angX[i]-90); A[i]down:=dir(angX[i]+180); |
| 523 |
endfor |
| 524 |
for i=1 upto cntB: |
| 525 |
B[i]s:=posA[sB[i]]; B[i]e:=posA[eB[i]]; B[i]m:=0.5[B[i]s,B[i]e]; B[i]:=B[i]s--B[i]e; |
| 526 |
B[i]ang:=angB[i]; B[i]up:=dir(angB[i]); |
| 527 |
B[i]down:=dir(angB[i]+180); B[i]left:=dir(angB[i]+90); B[i]right:=dir(angB[i]-90); |
| 528 |
endfor |
| 529 |
t addto mol_pic[cntM] also currentpicture; |
| 530 |
clearit; |
| 531 |
endgroup; % [;] |
| 532 |
enddef; |
| 533 |
%------------------------------------------------------------------------------------------------- |
| 534 |
def ext_to_fig(text t)= |
| 535 |
begingroup |
| 536 |
save w,h,An,Bn,wd,ht,n,p,am,aw,__,#,<<,=>,/*; |
| 537 |
pair __,p[]; |
| 538 |
ext_setup; |
| 539 |
w:=xpart fsize; h:=ypart fsize; |
| 540 |
w0:=w-2xpart fmargin; h0:=h-2ypart fmargin; p0:=fmargin; aw:=atom_wd; n:=cntM; |
| 541 |
for i=1 upto n: p[i]:=posM[1][i]; w[i]:=wdM[i]; h[i]:=htM[i]; endfor |
| 542 |
t addto mol_pic[0] also currentpicture; clearit; f_ext:=1; |
| 543 |
endgroup; % [;] |
| 544 |
enddef; |
| 545 |
%------------------------------------------------------------------------------------------------- |
| 546 |
vardef circled_plus_add= nA:=circlediam; nB:=circlepen; |
| 547 |
image(draw fullcircle scaled nA wpcs nB; |
| 548 |
draw (-.5nA,0)--(.5nA,0) wpcs nB; draw (0,-.5nA)--(0,.5nA) wpcs nB;) enddef; |
| 549 |
vardef circled_minus_add= nA:=circlediam; nB:=circlepen; |
| 550 |
image(draw fullcircle scaled nA wpcs nB; draw (-.5nA,0)--(.5nA,0) wpcs nB;) enddef; |
| 551 |
vardef lone_pair_add expr n= |
| 552 |
image(draw (0,0) wpcs lonepairdiam; draw ((0,lonepairspace) rotated n) wpcs lonepairdiam;) |
| 553 |
enddef; |
| 554 |
%================================================================================================= |
| 555 |
def drawm(expr s)= |
| 556 |
begingroup |
| 557 |
save temp_strA,temp_cntB,f_bra,f_term,f_at,f_lineT,f_rotT,f_lenT,f_envT,angL,cpos,tpos,factor, |
| 558 |
m_wd,m_ht,slen,sdir,char_wd,char_ht,tcol,f_col,knownA,markA,markB,saveA,saveB, |
| 559 |
lenC,lenL,lenT,lineT,angT,rotT,envT,envB,posBs,posBe,grp_cnt,grp_parts,grp_line, |
| 560 |
grp_len,grp_env,grp_rot,colorA,colorB,save_lenS,save_lenL,spos,slen, |
| 561 |
aW,aH,fW,fH,hW,hH,qH,fP,hP,ww,aw,ap,am,Ls,Le,pA,zA,zL; |
| 562 |
numeric grp_adr[],grp_line[],grp_len[],grp_env[],grp_rot[],grp_parts[],grp_lenL[],colorA[], |
| 563 |
colorB[]; |
| 564 |
pair cpos,tpos,spos,posBs,posBe,pA,Ls,Le; |
| 565 |
path frameA[],zA,zL; |
| 566 |
%----------------------------------------------------------------------------------------------- |
| 567 |
if f_expand=1: lenC:=1; else: lenC:=-ratio_chain_ring; fi |
| 568 |
cntA:=cntB:=cntC:=grp_num:=0; str_tbl[0]:="C"; str_cnt:=2000; save_lenL:=save_lenS:=lenC; |
| 569 |
fig_wd:=xpart fsize; fig_ht:=ypart fsize; |
| 570 |
%=============================================================================================== |
| 571 |
read_mcf_string(s); |
| 572 |
proc_bond_atom(1); |
| 573 |
backboneA:=cntA; backboneB:=cntB; |
| 574 |
if (grp_num>0)and(not scan_bit(sw_omit,Group)): expand_grp(1); fi |
| 575 |
%-scaling--------------------------------------------------------------------------------------- |
| 576 |
if blength>1: blen:=blength; proc_size_setup; proc_skeleton; proc_scaling; |
| 577 |
ef blength>0: blen:=fig_wd*blength; proc_size_setup; proc_skeleton; proc_scaling; |
| 578 |
else: |
| 579 |
blen:=3mm; |
| 580 |
proc_size_setup; |
| 581 |
if xpart msize<1: m_wd:=fig_wd*xpart msize; else: m_wd:=fig_wd; fi |
| 582 |
if ypart msize<1: m_ht:=fig_ht*ypart msize; else: m_ht:=fig_ht; fi |
| 583 |
for i=1 upto 6: |
| 584 |
proc_skeleton; proc_scaling; |
| 585 |
if (mol_ht/mol_wd)>(m_ht/m_wd): |
| 586 |
if ypart msize>1: factor:=ypart msize/mol_ht; |
| 587 |
else: factor:=((fig_ht-2ypart fmargin)*ypart msize)/mol_ht; fi |
| 588 |
else: if xpart msize>1: factor:=xpart msize/mol_wd; |
| 589 |
else: factor:=((fig_wd-2xpart fmargin)*xpart msize)/mol_wd; fi fi |
| 590 |
exitif (factor>=1-eps)and(factor<=1+eps); blen:=blen*factor; proc_size_setup; |
| 591 |
endfor |
| 592 |
if blen>max_blength: blen:=max_blength; proc_size_setup; proc_skeleton; proc_scaling; fi |
| 593 |
fi |
| 594 |
%----------------------------------------------------------------------------------------------- |
| 595 |
for i=1 upto cntA: |
| 596 |
if addA[i]<>0: |
| 597 |
if addA[i]=PLS: chargeA[i]:=1; ef addA[i]=MIS: chargeA[i]:=-1; else: chargeA[i]:=0; fi |
| 598 |
else: chargeA[i]:=0; fi |
| 599 |
endfor |
| 600 |
%=============================================================================================== |
| 601 |
if scan_bit(sw_output,Fig): |
| 602 |
%-draw atom----------------------------------------------------------------------------------- |
| 603 |
if sw_numbering=0: for i=1 upto cntA: if strA[i]<>0: draw_atom i; fi endfor fi |
| 604 |
%-draw add to atom---------------------------------------------------------------------------- |
| 605 |
if (not scan_bit(sw_numbering,Atom))and(not scan_bit(sw_numbering,Bond)): |
| 606 |
for i=1 upto cntA: |
| 607 |
if addA[i]<>0: draw_char(char(addA[i]),sfrt(posA[i],atom_wd,angX[i]+add_rot[i])); fi |
| 608 |
endfor fi |
| 609 |
%-draw bond----------------------------------------------------------------------------------- |
| 610 |
for i=1 upto cntB: if lineB[i]<si_ : draw_bond i; fi endfor |
| 611 |
for i=1 upto cntB: if lineB[i]>=si_: draw_bond i; fi endfor |
| 612 |
%-atom numbering------------------------------------------------------------------------------ |
| 613 |
if scan_bit(sw_numbering,Atom): |
| 614 |
if scan_bit(sw_numbering,All): numbering_end:=cntA; else: numbering_end:=backboneA; fi |
| 615 |
for i=1 upto numbering_end: |
| 616 |
defaultscale:=.2blen/defaultsize; nH:=1.2defaultsize*defaultscale; |
| 617 |
if i<=9: nW:=nH; ef i<=99: nW:=1.3nH; else: nW:=1.9nH; fi |
| 618 |
erase fill fullcircle xscaled 1.1nW yscaled 1.1nH shifted posA[i] wpcs 0.1; |
| 619 |
draw fullcircle xscaled 1.1nW yscaled 1.1nH shifted posA[i] wpcs 0.1; |
| 620 |
if numberfont="draw": draw_number(i,posA[i]); else: label(decimal i,posA[i]); fi |
| 621 |
endfor |
| 622 |
fi |
| 623 |
%-bond numbering------------------------------------------------------------------------------ |
| 624 |
if scan_bit(sw_numbering,Bond): |
| 625 |
if scan_bit(sw_numbering,All): numbering_end:=cntB; else: numbering_end:=backboneB; fi |
| 626 |
for i=1 upto numbering_end: |
| 627 |
defaultscale:=.18blen/defaultsize; nH:=1.2defaultsize*defaultscale; |
| 628 |
if i<=9: nW:=nH; ef i<=99: nW:=1.3nH; else: nW:=1.9nH; fi |
| 629 |
nH:=defaultsize*defaultscale; tpos:=.5[posA[sB[i]],posA[eB[i]]]; |
| 630 |
erase fill unitsquare xscaled nW yscaled 1.05nH shifted (tpos-(nW/2,1.05nH/2)); |
| 631 |
draw unitsquare xscaled nW yscaled 1.05nH shifted (tpos-(nW/2,1.05nH/2)) wpcs 0.1; |
| 632 |
if numberfont="draw": draw_number(i,tpos); else: label(decimal i,tpos); fi |
| 633 |
endfor |
| 634 |
fi |
| 635 |
%-make picture ------------------------------------------------------------------------------- |
| 636 |
if xpart mposition>1: nX:=xpart mposition-minX; |
| 637 |
else: nX:=xpart fmargin-minX+(fig_wd-mol_wd-2xpart fmargin)*xpart mposition; fi |
| 638 |
if ypart mposition>1: nY:=ypart mposition-minY; |
| 639 |
else: nY:=ypart fmargin-minY+(fig_ht-mol_ht-2ypart fmargin)*ypart mposition; fi |
| 640 |
posM[0][incr cntM]:=(nX,nY); posM1[cntM]:=(minX+nX,minY+nY); posM2[cntM]:=(maxX+nX,maxY+nY); |
| 641 |
wdM[cntM]:=mol_wd; htM[cntM]:=mol_ht; |
| 642 |
mol_pic[cntM]:=currentpicture; |
| 643 |
clearit; |
| 644 |
fi |
| 645 |
%-Calculate information ------------------------------------------------------------------------ |
| 646 |
MW_n:=MI_n:=tbl_atom_max:=warning_cnt:=hideH_cnt:=0; nA:=pc_emb_start; |
| 647 |
for i=1 upto tbl_atom_end: sumA[i]:=0; endfor |
| 648 |
for i=1 upto cntA: |
| 649 |
knownA:=bond_cntA:=0; nS:=strA[i]; |
| 650 |
for j=1 upto cntB: bond_num[j]:=bond_type(lineB[j]); |
| 651 |
if (sB[j]=i)or(eB[j]=i): bond_cntA:=bond_cntA+bond_num[j]; fi |
| 652 |
endfor |
| 653 |
Bcnt[i]:=bond_cntA; |
| 654 |
if ((nS=0)or(nS=C-nA))and(bond_cntA<4): hideH[i]:=4-bond_cntA; hideH_cnt:=hideH_cnt+hideH[i]; |
| 655 |
else: hideH[i]:=0; fi |
| 656 |
if (nS=0)or(nS=C-nA): if bond_cntA>4: warn_valence(i) fi |
| 657 |
ef nS=(O-nA): if bond_cntA<>2: warn_valence(i) fi |
| 658 |
ef nS=(N-nA): if (bond_cntA<>3)and(bond_cntA<>5): warn_valence(i) fi |
| 659 |
ef nS=(S-nA): if (bond_cntA<>2)and(bond_cntA<>4)and(bond_cntA<>6): warn_valence(i) fi |
| 660 |
ef nS=(P-nA): if bond_cntA<>5: warn_valence(i) fi |
| 661 |
ef (nS=H-nA)or(nS=OH-nA)or(nS=COOH-nA)or(nS=NH2-nA)or(nS=CN-nA)or(nS=F-nA)or |
| 662 |
(nS=Cl-nA)or(nS=Br-nA): if bond_cntA<>1: warn_valence(i) fi fi |
| 663 |
for j=1 upto tbl_grp_end: |
| 664 |
if str_tbl[nS]=tbl_atoms[j]: |
| 665 |
if tbl_atom[j]=0: sumA[j]:=sumA[j]+1; if j>tbl_atom_max: tbl_atom_max:=j; fi |
| 666 |
else: for k=1 upto tbl_atom[j]: |
| 667 |
sumA[tbl_grp[j][k]]:=sumA[tbl_grp[j][k]]+1; |
| 668 |
if tbl_grp[j][k]>tbl_atom_max: tbl_atom_max:=tbl_grp[j][k]; fi |
| 669 |
endfor fi |
| 670 |
knownA:=1; fi |
| 671 |
exitif knownA=1; |
| 672 |
endfor |
| 673 |
if knownA=0: message " Unknown Str("&str_tbl[strA[i]]&") is used "&decimal i; fi |
| 674 |
endfor |
| 675 |
sumA[2]:=sumA[2]+hideH_cnt; if (tbl_atom_max=1)and(sumA[2]>0): tbl_atom_max:=2; fi |
| 676 |
for i=1 upto tbl_atom_max: |
| 677 |
if sumA[i]>=1: MW_n:= MW_n+tbl_atom_wt[i]*sumA[i]; MI_n:= MI_n+tbl_atom_mi[i]*sumA[i]; |
| 678 |
fm:=fm&erase_char(tbl_atoms[i]) if sumA[i]>=2: &decimal sumA[i] fi; fi |
| 679 |
endfor |
| 680 |
mw:=substring(0,8) of decimal MW_n; mi:=substring(0,8) of decimal MI_n; |
| 681 |
endgroup; % [;] |
| 682 |
enddef; |
| 683 |
%------------------------------------------------------------------------------------------------- |
| 684 |
def add_grp expr p= |
| 685 |
if f_at=1: nA:=adrT; else: nA:=cntA+1; fi |
| 686 |
if checkA nA: |
| 687 |
grp_adr[incr grp_num]:=nA; |
| 688 |
if lenL<>lenC: if lenL>=0: grp_len[grp_num]:=grp_lenL[grp_num]:=-lenL; |
| 689 |
else: grp_len[grp_num]:=grp_lenL[grp_num]:=lenL; fi |
| 690 |
else: grp_len[grp_num]:=lenT; grp_lenL[grp_num]:=lenC; fi |
| 691 |
grp_line[grp_num]:=lineT; grp_env[grp_num]:=envT; |
| 692 |
grp_rot[grp_num]:=rotT; grp_parts[grp_num]:=p; |
| 693 |
if f_lineT=0: lineT:=si; fi |
| 694 |
if f_lenT=0: lenT:=lenC; fi |
| 695 |
if f_rotT=0: rotT:=0; fi |
| 696 |
if f_envT=0: envT:=hz; fi |
| 697 |
fi |
| 698 |
enddef; |
| 699 |
%------------------------------------------------------------------------------------------------- |
| 700 |
def expand_grp(expr n)= |
| 701 |
save_grp_num:=grp_num; save_mc_cnt:=mc_cnt; |
| 702 |
for i=n upto grp_num: |
| 703 |
put_grp(_jp_absA,grp_adr[i]) put_grp(_com,_mark) |
| 704 |
if grp_line[i]<>si: |
| 705 |
if grp_line[i]=nl: put_grp(_tmp_len,_size_atom) put_grp(_adj_ang,0) fi |
| 706 |
put_grp(_tmp_line,grp_line[i]) fi |
| 707 |
if (grp_len[i]<>lenC)and(grp_line[i]<>nl): put_grp(_tmp_len,grp_len[i]) fi |
| 708 |
if grp_env[i]<>hz: put_grp(_chg_env,grp_env[i]) fi |
| 709 |
put_grp(_mk_bond,grp_rot[i]) |
| 710 |
if grp_parts[i]<>NO_ATOM: |
| 711 |
if grp_lenL[i]<>lenC: put_grp(_chg_len,grp_lenL[i]) fi |
| 712 |
for j=1 upto pc_cnt[grp_parts[i]]: |
| 713 |
if pc_x[grp_parts[i]][j]>=pc_emb_start: expand_pcode(pc_x[grp_parts[i]][j],0) |
| 714 |
else: put_grp(pc_x[grp_parts[i]][j],pc_y[grp_parts[i]][j]) fi |
| 715 |
endfor |
| 716 |
fi |
| 717 |
put_grp(_chg_env,hz) put_grp(_com,_term) put_grp(_com,_rest) put_grp(_chg_len,_end) |
| 718 |
endfor |
| 719 |
proc_bond_atom(save_mc_cnt+1); |
| 720 |
if grp_num>save_grp_num: expand_grp(save_grp_num+1); fi |
| 721 |
enddef; |
| 722 |
%------------------------------------------------------------------------------------------------- |
| 723 |
def put_grp(expr x,y)= mc_x[incr mc_cnt]:=x; mc_y[mc_cnt]:=y; mc_b[mc_cnt]:=0; enddef; |
| 724 |
%================================================================================================= |
| 725 |
def draw_frame(expr o,p,n)= |
| 726 |
draw ((0,0)--(xpart p,0)--p--(0,ypart p)--cycle) shifted o withpen pensquare scaled n; enddef; |
| 727 |
def draw_corner(expr p,n)= |
| 728 |
draw (0,0) wpcs n; draw(xpart p,0) wpcs n; draw p wpcs n; draw(0,ypart p) wpcs n; enddef; |
| 729 |
%------------------------------------------------------------------------------------------------- |
| 730 |
def proc_size_setup= |
| 731 |
atom_wd:= blen*ratio_atom_bond+offset_atom; |
| 732 |
wedge_wd:= blen*ratio_wedge_bond+offset_wedge; |
| 733 |
hash_gap:= blen*ratio_hashgap_bond+offset_hash_gap; |
| 734 |
bondgap:= blen*ratio_bondgap_bond+offset_bond_gap; |
| 735 |
bond_pen_wd:= blen*ratio_thickness_bond+offset_thickness; |
| 736 |
enddef; |
| 737 |
%------------------------------------------------------------------------------------------------- |
| 738 |
def proc_scaling= |
| 739 |
minX:=minY:=4095; maxX:=maxY:=-4095; |
| 740 |
for i=1 upto cntA: |
| 741 |
nX:=xpart posA[i]; nY:=ypart posA[i]; |
| 742 |
if strA[i]<>0: |
| 743 |
nU:=nD:=nP:=nL:=nR:=0; |
| 744 |
for j=1 upto length str_tbl[strA[i]]: |
| 745 |
tempc:=substring(j-1,j) of str_tbl[strA[i]]; |
| 746 |
if tempc="^": nU:=.5atom_wd; ef tempc="_": nD:=.5atom_wd; |
| 747 |
ef (tempc<>"{")and(tempc<>"}"): nP:=nP+atom_wd*tbl_char_wd[ASCII(tempc)]; fi |
| 748 |
endfor |
| 749 |
if (angX[i]<=90)or(angX[i]>=270): nR:=nP; else: nL:=nP; fi |
| 750 |
if (nX-nL+.5atom_wd)<minX: minX:=nX-nL+.5atom_wd; fi |
| 751 |
if (nX+nR-.5atom_wd)>maxX: maxX:=nX+nR-.5atom_wd; fi |
| 752 |
if (nY-nD-.5atom_wd)<minY: minY:=nY-nD-.5atom_wd; fi |
| 753 |
if (nY+nU+.5atom_wd)>maxY: maxY:=nY+nU+.5atom_wd; fi |
| 754 |
else: if nX<minX: minX:=nX; fi if nX>maxX: maxX:=nX; fi |
| 755 |
if nY<minY: minY:=nY; fi if nY>maxY: maxY:=nY; fi fi |
| 756 |
endfor |
| 757 |
mol_wd:=maxX-minX; mol_ht:=maxY-minY; |
| 758 |
enddef; |
| 759 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 760 |
def proc_bond_atom(expr n)= |
| 761 |
f_bra:=f_term:=rotT:=f_lineT:=f_rotT:=f_lenT:=f_envT:=temp_strA:=f_at:=f_inv:=addAT:=markA:=0; |
| 762 |
markB:=saveA:=saveB:=sB[0]:=0; eB[0]:=1; lenL:=lenT:=lenC; lineT:=si; envB:=envT:=hz; |
| 763 |
%----------------------------------------------------------------------------------------------- |
| 764 |
for i=n upto mc_cnt: |
| 765 |
pX:=mc_x[i]; pY:=mc_y[i]; pB:=mc_b[i]; |
| 766 |
if pX=_mk_bond: if (pY=0)and(rotT<>0): rotT:=0; fi add_atom 0; |
| 767 |
ef pX=_set_adrA: if (pY mod 1)>0: f_inv:=1; pY:=round pY; fi adrT:=getA pY; |
| 768 |
ef pX=_set_adrB: if (pY mod 1)>0: f_inv:=1; pY:=round pY; fi adrT:=getB pY; |
| 769 |
ef pX=_com: if pY=_mark: saveA:=markA; saveB:=markB; markA:=cntA; markB:=cntB; |
| 770 |
ef pY=_rest: markA:=saveA; markB:=saveB; |
| 771 |
ef pY=_moff: markA:=markB:=0; |
| 772 |
ef pY=_term: termA; |
| 773 |
ef pY=_grp_s: f_at:=1; if lineT<>si: f_lineT:=1; fi if rotT<>0: f_rotT:=1; fi |
| 774 |
if lenT<>lenC: f_lenT:=1; fi if envT<>hz: f_envT:=1; fi |
| 775 |
ef pY=_grp_e: f_at:=f_lineT:=f_rotT:=f_lenT:=f_envT:=rotT:=0; |
| 776 |
lineT:=si; lenT:=lenC; envT:=hz; fi |
| 777 |
ef pX=_set_atom: temp_strA:=pY; |
| 778 |
ef pX=_grp_si: add_grp pY; |
| 779 |
ef pX=_grp_dm: lineT:=dm; add_grp pY; |
| 780 |
ef pX=_grp_wf: if f_inv=1: lineT:=zf; f_inv:=0; else: lineT:=wf; fi add_grp pY; |
| 781 |
ef pX=_grp_zf: if f_inv=1: lineT:=wf; f_inv:=0; else: lineT:=zf; fi add_grp pY; |
| 782 |
ef pX=_jp_bond: nB:=getB pY; nB:=checkBn nB; termA; sB[cntB+1]:=sB[nB]; f_bra:=1; |
| 783 |
ef pX=_jp_atom: nA:=getA pY; nA:=checkAn nA; termA; sB[cntB+1]:=nA; f_bra:=1; |
| 784 |
ef pX=_jp_absA: sB[cntB+1]:=pY; f_bra:=1; temp_cntB:=cntB; |
| 785 |
ef pX=_chg_atom: if checkA adrT: strA[adrT]:=pc_y[pY][1]; fi |
| 786 |
ef pX=_tmp_len: lenT:=pY; |
| 787 |
ef pX=_chg_len: if pY=_end: lenL:=save_lenS; else: save_lenS:=lenL; lenL:=pY; fi |
| 788 |
ef pX=_set_len: if pY=_end: lenL:=save_lenL; |
| 789 |
ef pY=_ring: save_lenL:=lenL; if lenT<>lenC:lenL:=lenT; ef lenL<0:lenL:=1; fi |
| 790 |
ef pY=_chain: save_lenL:=lenL; if lenT<>lenC:lenL:=lenT; fi |
| 791 |
else: save_lenL:=lenL; lenL:=pY; fi |
| 792 |
ef pX=_get_len: nB:=getB pY; save_lenL:=lenL; lenL:=lenB[nB]; |
| 793 |
ef pX=_set_line: if checkB adrT: |
| 794 |
if f_inv=1: f_inv:=0; if pY=dl: pY:=dr; ef pY=dr: pY:=dl; fi fi |
| 795 |
lineB[adrT]:=pY; fi |
| 796 |
ef pX=_tmp_line: lineT:=pY; |
| 797 |
ef pX=_tmp_rot: rotT:=pY; |
| 798 |
ef pX=_cyc: nA:=getA pY; nA:=checkAn nA; add_atom nA; |
| 799 |
ef pX=_cyc_eB: nB:=getB pY; nB:=checkBn nB; add_atom eB[nB]; |
| 800 |
ef pX=_cyc_sB: nB:=getB pY; nB:=checkBn nB; add_atom sB[nB]; |
| 801 |
ef pX=_chg_env: envB:=pY; |
| 802 |
ef pX=_tmp_env: envT:=pY; |
| 803 |
ef pX=_set_colorA: colorA[adrT]:=pY; |
| 804 |
ef pX=_set_colorB: colorB[adrT]:=pY; |
| 805 |
ef pX=_add_charge: addAT:=pY; |
| 806 |
ef pX=_set_charge: if checkA adrT: addA[adrT]:=pY; if rotT<>0: add_rot[adrT]:=rotT; fi fi |
| 807 |
fi |
| 808 |
endfor |
| 809 |
enddef; |
| 810 |
%------------------------------------------------------------------------------------------------- |
| 811 |
def add_atom expr n= |
| 812 |
lineB[incr cntB]:=lineT; lineT:=si; |
| 813 |
if lenT=lenC: lenB[cntB]:=lenL; else: lenB[cntB]:=lenT; lenT:=lenC; fi |
| 814 |
if f_bra=0: strA[incr cntA]:=temp_strA; sB[cntB]:=cntA; |
| 815 |
addA[cntA]:=addAT; addAT:=temp_strA:=add_rot[cntA]:=0; |
| 816 |
if rotT<>0: add_rot[cntA]:=rotT; rotT:=0; fi |
| 817 |
else: f_bra:=0; fi |
| 818 |
if n=0: eB[cntB]:=cntA+1; f_term:=0; else: eB[cntB]:=n; f_term:=1; fi |
| 819 |
enddef; |
| 820 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 821 |
def proc_skeleton= |
| 822 |
markA:=markB:=cntA:=cntB:=f_bra:=rotT:=f_term:=angA[0]:=angB[0]:=angX[0]:=0; |
| 823 |
lineT:=si; envT:=envB:=hz; angT:=mangle; posA[0]:=posBs:=posBe:=(0,0); |
| 824 |
%----------------------------------------------------------------------------------------------- |
| 825 |
for i=1 upto mc_cnt: pX:=mc_x[i]; pY:=mc_y[i]; pB:=mc_b[i]; |
| 826 |
if pX=_mk_bond: if (pY=0)and(rotT<>0):pY:=rotT; rotT:=0; fi add_bond(pY,1); |
| 827 |
ef pX=_com: if pY=_mark: saveA:=markA; saveB:=markB; markA:=cntA; markB:=cntB; |
| 828 |
ef pY=_rest: markA:=saveA; markB:=saveB; |
| 829 |
ef pY=_moff: markA:=markB:=0; ef pY=_term: termB; fi |
| 830 |
ef pX=_jp_bond: adrT:=getB pY; adrT:=checkBn adrT; |
| 831 |
termB; posBs:=posA[sB[adrT]]; angT:=angB[adrT]; f_bra:=1; rotT:=0; |
| 832 |
ef pX=_jp_atom: adrT:=getA pY; adrT:=checkAn adrT; |
| 833 |
termB; posBs:=posA[adrT]; angT:=angX[adrT]; f_bra:=1; rotT:=0; |
| 834 |
ef pX=_jp_absA: adrT:=pY; posBs:=posA[adrT]; angT:=angX[adrT]; |
| 835 |
f_bra:=1; rotT:=0; temp_cntB:=cntB; |
| 836 |
ef pX=_adj_ang: angT:=adjust_ang(angT); |
| 837 |
ef pX=_rot_ang: if pY>-3700: angT:=(angT+pY) mod 360; else: angT:=(pY+4095) mod 360; fi |
| 838 |
ef pX=_tmp_rot: rotT:=pY; |
| 839 |
ef pX=_chg_env: envB:=pY; |
| 840 |
ef pX=_tmp_env: envT:=pY; |
| 841 |
ef pX=_cyc: nA:=getA pY; nA:=checkAn nA; add_bond(angle(posA[nA]-posBs)-angT,0); |
| 842 |
ef pX=_cyc_sB: nA:=getB pY; nA:=checkBn nA; add_bond(angle(posA[sB[nA]]-posBs)-angT,0); |
| 843 |
ef pX=_cyc_eB: nA:=getB pY; nA:=checkBn nA; add_bond(angle(posA[eB[nA]]-posBs)-angT,0); |
| 844 |
fi |
| 845 |
endfor |
| 846 |
enddef; |
| 847 |
%------------------------------------------------------------------------------------------------- |
| 848 |
def add_bond(expr n,f)= |
| 849 |
if n=_auto_ang: nA:=arrange_ang(angT mod 360); else: nA:=n; fi |
| 850 |
if f_bra=0: |
| 851 |
adrT:=incr cntA; posA[cntA]:=posBs; angA[cntA]:=angT; |
| 852 |
angX[cntA]:=(angT+nA/2+iif(nA>=0,-90,90)) mod 360; |
| 853 |
else: f_bra:=0; fi |
| 854 |
cntB:=cntB+1; |
| 855 |
if nA>-3700: angB[cntB]:=angT:=(angT+nA) mod 360; else: angB[cntB]:=angT:=nA+4095; fi |
| 856 |
if f=1: |
| 857 |
if lenB[cntB]=_size_atom: posBe:=sfrt(posBs,1.1atom_wd,angT); |
| 858 |
else: nA:=lenB[cntB]; if nA<0:nB:=glu_atom(adrT)+glu_atom(cntA+1); nA:=abs nA; else:nB:=0; fi |
| 859 |
posBe:=sfrt(posBs,nA*blen+nB,angT); fi |
| 860 |
posA[cntA+1]:=posBe; f_term:=0; |
| 861 |
else: f_term:=1; fi |
| 862 |
posBs:=posBe; |
| 863 |
enddef; |
| 864 |
%------------------------------------------------------------------------------------------------- |
| 865 |
vardef arrange_ang(expr n)= |
| 866 |
if f_bra=1: 0 |
| 867 |
else: if cntB=0: angT:=(angT-180) mod 360; 180 |
| 868 |
else: if envB>=pc_emb_start: pc_y[envB][cntB-temp_cntB] |
| 869 |
else: if envB=hz: if n=0:60 ef n<=90:-60 ef n<=180:60 ef n<270:-60 else:60 fi |
| 870 |
ef envB=vt: if n=0:-60 ef n<90:60 ef n<=180:-60 ef n<=270:60 else:-60 fi |
| 871 |
ef envB=lr: if odd(cntB-temp_cntB):60 else:-60 fi |
| 872 |
ef envB=rl: if odd(cntB-temp_cntB):-60 else:60 fi |
| 873 |
ef envB=ll: 60 |
| 874 |
ef envB=rr: -60 |
| 875 |
ef abs envB<=180: envB fi fi fi |
| 876 |
fi |
| 877 |
enddef; |
| 878 |
%------------------------------------------------------------------------------------------------- |
| 879 |
vardef adjust_ang(expr n)= if (n<40)or(n>320): 0 ef n<140: 90 ef n<220: 180 else: 270 fi enddef; |
| 880 |
%================================================================================================= |
| 881 |
vardef getA expr n= if n>=0: markA+n ef n>=-999: cntA+n+1 else: n+4095 fi enddef; |
| 882 |
vardef getB expr n= if n>=0: markB+n ef n>=-999: cntB+n+1 else: n+4095 fi enddef; |
| 883 |
vardef checkA expr n= |
| 884 |
bA:=(n<=(cntA+iif(f_term=0,1,0)))and(n>=1)and(n mod 1=0); if not bA: message_error(pB,1) fi bA |
| 885 |
enddef; |
| 886 |
vardef checkB expr n= bA:=(n<=cntB)and(n>=1)and(n mod 1=0); if not bA: message_error(pB,2) fi bA |
| 887 |
enddef; |
| 888 |
vardef checkAn expr n= if checkA n: n else: 1 fi enddef; |
| 889 |
vardef checkBn expr n= if checkB n: n else: 1 fi enddef; |
| 890 |
%------------------------------------------------------------------------------------------------- |
| 891 |
def termA= |
| 892 |
if f_term=0: if f_bra=0: strA[incr cntA]:=temp_strA; addA[cntA]:=addAT; add_rot[cntA]:=rotT; |
| 893 |
addAT:=temp_strA:=rotT:=0; |
| 894 |
else: f_bra:=0; fi |
| 895 |
f_term:=1; fi |
| 896 |
enddef; |
| 897 |
def termB= if f_term=0: if f_bra=0: angX[incr cntA]:=angT; else:f_bra:=0; fi f_term:=1; fi enddef; |
| 898 |
%------------------------------------------------------------------------------------------------- |
| 899 |
vardef glu_atom(expr n)= |
| 900 |
if strA[n]<>0: nD:=angT mod 90; nC:=0.5atom_wd; nN:=(iif(nD<45,sind nD,cosd nD)*nC)PADD nC; nN |
| 901 |
else: 0 fi |
| 902 |
enddef; |
| 903 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 904 |
def draw_atom expr n= |
| 905 |
if atomfont<>"draw": defaultfont:=atomfont; defaultsize:=atom_wd; fi |
| 906 |
atoms:=str_tbl[strA[n]]; slen:=length atoms; nC:=nS:=nP:=0; tpos:=posA[n]; |
| 907 |
if (angX[n]<=90)or(angX[n]>=270): sdir:=1; else: sdir:=-1; fi |
| 908 |
for i=1 upto slen: |
| 909 |
if nC=0: tempc:=subc(atoms,i); |
| 910 |
if (sdir=-1)and(tempc="{"): |
| 911 |
nD:=i; nC:=0; for j=nD upto slen: nC:=nC+1; exitif subc(atoms,j+1)="}"; endfor |
| 912 |
fi |
| 913 |
else: nC:=nC-1; tempc:=subc(atoms,nD+nC); |
| 914 |
fi |
| 915 |
if tempc="_": nP:=iif(nP=0,-.5atom_wd,0); |
| 916 |
ef tempc="^": nP:=iif(nP=0, .5atom_wd,0); |
| 917 |
ef (tempc<>"{")and(tempc<>"}"): |
| 918 |
nS:=nS+1; char_wd:=atom_wd*tbl_char_wd[ASCII(tempc)]; char_ht:=atom_wd; |
| 919 |
if nS=1: if (sdir=-1)and(char_wd<atom_wd): tpos:=tpos+((atom_wd-char_wd)/2,0); fi |
| 920 |
else: tpos:=tpos+(.5char_wd*sdir,0); fi |
| 921 |
tcol:=colorA[n]; f_col:=0; |
| 922 |
if known tcol: if tcol<>0: drawoptions(withcolor color_list[tcol]); f_col:=1; fi fi |
| 923 |
if atomfont="draw": draw_char(tempc,tpos+(0,nP)); else: label(tempc,tpos+(0,nP)); fi |
| 924 |
if f_col=1: drawoptions(); fi |
| 925 |
tpos:=tpos+(.5char_wd*sdir,0); |
| 926 |
fi |
| 927 |
endfor |
| 928 |
nA:=0.56atom_wd; nB:=0.06atom_wd; |
| 929 |
if sdir=1: frameA[n]:=posA[n]-(nA,nA)--tpos+(nB,-nA)--tpos+(nB,nA)--posA[n]+(-nA,nA)--cycle; |
| 930 |
else: frameA[n]:=tpos-(nB,nA)--posA[n]+(nA,-nA)--posA[n]+(nA,nA)--tpos+(-nB,nA)--cycle; fi |
| 931 |
if scan_bit(sw_frame,Atom): draw frameA[n] wpcs thickness_frame; fi |
| 932 |
enddef; |
| 933 |
%------------------------------------------------------------------------------------------------- |
| 934 |
def draw_number(expr n,p)= |
| 935 |
atom_wd:=.18blen; bond_pen_wd:=.012blen; temps:=decimal n; slen:=length temps; spos:=p; |
| 936 |
for i=1 upto slen: |
| 937 |
if i=1: spos:=spos-(slen*.35atom_wd-.35atom_wd,0); else: spos:=spos+(0.73atom_wd,0); fi |
| 938 |
draw_char(substring(i-1,i) of temps,spos); |
| 939 |
endfor |
| 940 |
enddef; |
| 941 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 942 |
def draw_bond expr n= |
| 943 |
nL:=lineB[n]; angL:=angB[n]; nS:=sB[n]; nE:=eB[n]; f_col:=0; |
| 944 |
tcol:=colorB[n]; zL:=posA[nS]--posA[nE]; ww:=wedge_wd; ap:=angL+90; am:=angL-90; aw:=atom_wd; |
| 945 |
%----------------------------------------------------------------------------------------------- |
| 946 |
if (strA[nS]=0)and(strA[nE]=0)or(sw_numbering>=1): Ls:=posA[nS]; Le:=posA[nE]; pA:=(.1,.9); |
| 947 |
ef strA[nS]=0: Ls:=posA[nS]; Le:=zL intersectionpoint frameA[nE]; pA:=(.15,1); |
| 948 |
ef strA[nE]=0: Ls:=zL intersectionpoint frameA[nS]; Le:=posA[nE]; pA:=(0,.85); |
| 949 |
else: Ls:=zL intersectionpoint frameA[nS]; Le:=zL intersectionpoint frameA[nE]; pA:=(0,1); fi |
| 950 |
zA:=Ls--Le; lenL:=length(Le-Ls); |
| 951 |
%----------------------------------------------------------------------------------------------- |
| 952 |
if known tcol: if tcol<>0: drawoptions(withcolor color_list[tcol]); f_col:=1;fi fi |
| 953 |
pickup pencircle scaled bond_pen_wd; |
| 954 |
if (nL=si)or(scan_bit(sw_omit,Bond)): draw zA; |
| 955 |
ef nL=dl: draw zA; draw sfrt(subpath pA of zA,bondgap,ap); |
| 956 |
ef nL=dr: draw zA; draw sfrt(subpath pA of zA,bondgap,am); |
| 957 |
ef nL=dm: draw sfrt(zA,bondgap/1.75,ap); draw sfrt(zA,bondgap/1.75,am); |
| 958 |
ef nL=db: nA:=iif(((angL-angX[nS]) mod 360)<=180,ap,am); |
| 959 |
draw zA; draw sfrt(subpath pA of zA,bondgap,nA); |
| 960 |
ef nL=wf: fill Ls--sfrt(Le,ww,am)--sfrt(Le,ww,ap)--cycle; |
| 961 |
ef nL=zf: wz_put(Ls,sfrt(Le,ww,ap),sfrt(Le,ww,am)); |
| 962 |
ef nL=nl: |
| 963 |
ef nL=wb: fill sfrt(Ls,ww,am)--Le--sfrt(Ls,ww,ap)--cycle; |
| 964 |
ef nL=tm: draw zA; draw sfrt(zA,bondgap,ap); draw sfrt(zA,bondgap,am); |
| 965 |
ef nL=bd: draw zA withpen penrazor rotated ap scaled bondgap; |
| 966 |
ef nL=bz: bz_put(sfrt(Ls,ww,ap),sfrt(Le,ww,ap),sfrt(Ls,ww,am),sfrt(Le,ww,am)); |
| 967 |
ef nL=zb: wz_put(Le,sfrt(Ls,ww,am),sfrt(Ls,ww,ap)); |
| 968 |
ef nL=dt: for i=0 step .75hash_gap/lenL until 1: drawdot i[Ls,Le] wpcs 2bond_pen_wd; endfor |
| 969 |
ef nL=wv: nA:=.4bondgap; nB:=round(lenL/nA); |
| 970 |
draw Ls for i=1 upto nB: ..controls(point (i-.5)/nB of sfrt(zA,nA,iif(odd i,ap,am))) |
| 971 |
..point i/nB of zA endfor |
| 972 |
ef nL=wf_r: filldraw Ls--sfrt(Le,.35ww,am)--sfrt(Le,.35ww,ap)--cycle wpcs .05ww; |
| 973 |
ef nL=wb_r: filldraw sfrt(Ls,.35ww,am)--Le--sfrt(Ls,.35ww,ap)--cycle wpcs .05ww; |
| 974 |
ef nL=bd_r: draw zA wpcs .65bondgap; |
| 975 |
ef nL=vf: draw zA;draw sfrt(Le,bondgap,angL-150)--Le--sfrt(Le,bondgap,angL+150); |
| 976 |
ef nL=vb: draw zA;draw sfrt(Ls,bondgap,angL-30)--Ls--sfrt(Ls,bondgap,angL+30); |
| 977 |
ef nL=si_: erase draw subpath (.15,.85) of zA wpcs 0.8bondgap; draw zA; |
| 978 |
ef nL=dl_: erase draw subpath (.15,.85) of sfrt(subpath pA of zA,.5bondgap,ap) wpcs 1.8bondgap; |
| 979 |
draw zA; draw sfrt(subpath pA of zA,bondgap,ap); |
| 980 |
ef nL=dr_: erase draw subpath (.15,.85) of sfrt(subpath pA of zA,.5bondgap,am) wpcs 1.8bondgap; |
| 981 |
draw zA; draw sfrt(subpath pA of zA,bondgap,am); |
| 982 |
ef nL=dm_: erase draw subpath(0.15,0.85) of zA wpcs 1.8 bondgap; |
| 983 |
draw sfrt(zA,bondgap/1.75,ap); draw sfrt(zA,bondgap/1.75,am); |
| 984 |
ef nL=wf_: erase draw subpath (0.15,0.85) of (Ls--sfrt(Le,ww,am)) wpcs 0.8bondgap; |
| 985 |
erase draw subpath (0.15,0.85) of (Ls--sfrt(Le,ww,ap)) wpcs 0.8bondgap; |
| 986 |
fill Ls--sfrt(Le,ww,am)--sfrt(Le,ww,ap)--cycle; |
| 987 |
ef nL=wb_: erase draw subpath (0.15,0.85) of (sfrt(Ls,ww,am)--Le) wpcs 0.8bondgap; |
| 988 |
erase draw subpath (0.15,0.85) of (sfrt(Ls,ww,ap)--Le) wpcs 0.8bondgap; |
| 989 |
fill sfrt(Ls,ww,am)--Le--sfrt(Ls,ww,ap)--cycle; |
| 990 |
ef nL=zf_: erase draw subpath (0.15,0.85) of (Ls--sfrt(Le,ww,am)) wpcs 0.8bondgap; |
| 991 |
erase draw subpath (0.15,0.85) of zA wpcs 0.8bondgap; |
| 992 |
erase draw subpath (0.15,0.85) of (Ls--sfrt(Le,ww,ap)) wpcs 0.8bondgap; |
| 993 |
wz_put(Ls,sfrt(Le,ww,ap),sfrt(Le,ww,am)); |
| 994 |
ef nL=zb_: erase draw subpath (0.15,0.85) of (sfrt(Ls,ww,am)--Le) wpcs 0.8bondgap; |
| 995 |
erase draw subpath (0.15,0.85) of zA wpcs 0.8bondgap; |
| 996 |
erase draw subpath (0.15,0.85) of (sfrt(Ls,ww,ap)--Le) wpcs 0.8bondgap; |
| 997 |
wz_put(Le,sfrt(Ls,ww,am),sfrt(Ls,ww,ap)); |
| 998 |
ef nL=bd_: erase draw subpath(0.15,0.85) of zA wpcs 1.6bondgap; |
| 999 |
draw zA withpen penrazor rotated ap scaled bondgap; |
| 1000 |
%-- bond type for glycan ---------------------------------------------------------------------- |
| 1001 |
ef nL=arc_lb: draw Ls--Ls-(0,aw)..posA[nE]+(-1.2aw,0)..posA[nE]-(.6aw,0); |
| 1002 |
ef nL=arc_br: draw posA[nS]+(.6aw,0)..posA[nS]+(1.2aw,0)..Le-(0,aw)--Le; |
| 1003 |
ef nL=arc_lbr: draw posA[nS]+(0,iif(strA[nS]=0,0,-.6aw))--posA[nS]+(0,-.8aw) |
| 1004 |
..0.5[posA[nS],posA[nE]]+(0,-1.7aw)..posA[nE]+(0,-.8aw) |
| 1005 |
--posA[nE]+(0,iif(strA[nE]=0,0,-.6aw)); |
| 1006 |
ef nL=arc_ltr: draw posA[nS]+(0,iif(strA[nS]=0,0,0.6aw))--posA[nS]+(0,.8aw) |
| 1007 |
..0.5[posA[nS],posA[nE]]+(0,1.7aw)..posA[nE]+(0,.8aw) |
| 1008 |
--posA[nE]+(0,iif(strA[nE]=0,0,.6aw)); fi |
| 1009 |
if f_col=1: drawoptions(); fi |
| 1010 |
enddef; |
| 1011 |
%------------------------------------------------------------------------------------------------ |
| 1012 |
def wz_put(expr a,b,c)= |
| 1013 |
nB:=round(lenL/hash_gap); |
| 1014 |
for i=1 upto nB: nA:=i/nB; if i=1: nD:=0; else: nD:=(i-ratio_hash_black)/nB; fi |
| 1015 |
fill nD[a,b]--nD[a,c]--nA[a,c]--nA[a,b]--cycle; |
| 1016 |
endfor |
| 1017 |
enddef; |
| 1018 |
def bz_put(expr a,b,c,d)= |
| 1019 |
nB:=round(lenL/hash_gap); |
| 1020 |
for i=0 upto nB-1: nA:=i/nB; nD:=nA+ratio_hash_black/nB; |
| 1021 |
fill nA[b,a]--nA[d,c]--nD[d,c]--nD[b,a]--cycle; |
| 1022 |
endfor |
| 1023 |
enddef; |
| 1024 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1025 |
def char_size_set(expr w,h)(expr s)= |
| 1026 |
for j=1 upto length s: nA:=ASCII(subc(s,j)); tbl_char_wd[nA]:=w; tbl_char_ht[nA]:=h; endfor |
| 1027 |
enddef; |
| 1028 |
%------------------------------------------------------------------------------------------------- |
| 1029 |
char_size_set( 1, 1)("CGHMNOQW"); |
| 1030 |
char_size_set( 0.9, 1)("ABDFIJKPRSTUVXY"); |
| 1031 |
char_size_set( 0.8, 1)("ELZ"); |
| 1032 |
char_size_set( 0.7, 1)("0123456789nhtfg"); |
| 1033 |
char_size_set( 0.7, 0.7)("-+"); |
| 1034 |
char_size_set(0.45,0.95)("l"); |
| 1035 |
char_size_set(0.75, 0.8)("opq"); |
| 1036 |
char_size_set( 0.8, 0.8)("e"); |
| 1037 |
char_size_set( 0.9, 0.8)("wm"); |
| 1038 |
char_size_set( 0.7, 0.8)("abdcksuvrxyz"); |
| 1039 |
char_size_set(0.35, 0.9)("i"); |
| 1040 |
char_size_set( 0.5, 0.9)("j"); |
| 1041 |
%------------------------------------------------------------------------------------------------- |
| 1042 |
def dw expr p = draw p shifted cpos enddef; |
| 1043 |
def dwv expr p = draw p withpen penrazor scaled fP shifted cpos enddef; |
| 1044 |
def dwvs(expr n) expr p = draw p withpen penrazor scaled (fP*n) shifted cpos enddef; |
| 1045 |
def dwh expr p = draw p withpen penrazor rotated 90 scaled fP shifted cpos enddef; |
| 1046 |
def cdw expr p = cutdraw p shifted cpos enddef; |
| 1047 |
%------------------------------------------------------------------------------------------------- |
| 1048 |
def Z_a=( 0,hP) enddef; def Z_b=(hP, 0) enddef; def Z_c=(hP,hP) enddef; def Z_d=(aW,hP) enddef; |
| 1049 |
def Z_e=(fW, 0) enddef; def Z_f=(hW,aH) enddef; def Z_g=(hW, 0) enddef; def Z_h=( 0,hH) enddef; |
| 1050 |
def Z_i=(hW,fW) enddef; def Z_j=( 0,qH) enddef; def Z_k=(aW,qH) enddef; def Z_l=(.75aW,0) enddef; |
| 1051 |
def Z_m=(hP,hH) enddef; def Z_n=(fW,fH) enddef; def Z_o=(fW,hH) enddef; def Z_p=(hW,aW) enddef; |
| 1052 |
def Z_q=( 0,fH) enddef; def Z_r=(hP,fH) enddef; def Z_s=(hW,fH) enddef; def Z_t=(fW,aH) enddef; |
| 1053 |
def Z_u=(aW,fH) enddef; def Z_v=(aW,hH) enddef; def Z_w=(hP,aH) enddef; def Z_x=(hW,hP) enddef; |
| 1054 |
def Z_y=(hW,hH) enddef; def Z_z=(fW,hP) enddef; |
| 1055 |
%------------------------------------------------------------------------------------------------- |
| 1056 |
def circ_O = Z_o..(.8aW,fH-qP)..tension 1.5..(.2aW,fH-qP)..Z_m.. |
| 1057 |
(.2aW,1.5hP)..tension 1.5..(.8aW,1.5hP)..cycle enddef; |
| 1058 |
def circ_Oh = (hP,qH)..Z_x..(fW,qH)..Z_y..cycle enddef; |
| 1059 |
def circ_sOh = (hP,qH)..Z_x..(.98fW,qH)..Z_y..cycle enddef; |
| 1060 |
def circ_Oa = (hP,0.35aH)..Z_x..(fW,0.35aH)..(hW,.7aH)..cycle enddef; |
| 1061 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1062 |
def draw_char(expr s,p)= |
| 1063 |
aW:=atom_wd*tbl_char_wd[ASCII(s)]*(1-2ratio_atomgap_atom); |
| 1064 |
aH:=atom_wd*tbl_char_ht[ASCII(s)]*(1-2ratio_atomgap_atom); |
| 1065 |
cpos:=p-(aW/2,atom_wd/2*(1-2ratio_atomgap_atom)); |
| 1066 |
fP:=atom_wd*ratio_char_atom; |
| 1067 |
hP:=fP/2; qP:=fP/4; fW:=aW-hP; hW:=aW/2; fH:=aH-hP; hH:=aH/2; qH:=aH/4; |
| 1068 |
%----------------------------------------------------------------------------------------------- |
| 1069 |
pickup pencircle scaled fP; |
| 1070 |
if s="C": cdw sbp(.05,.95)circ_O; |
| 1071 |
ef s="H": dwv Z_b--Z_w; dw Z_m--Z_o; dwv Z_e--Z_t; |
| 1072 |
ef s="O": dw circ_O; |
| 1073 |
ef s="N": dwv Z_b--Z_w; dwv Z_e--Z_t; dwvs(1.4)(1.4hP,aH)--(aW-1.4hP,0); |
| 1074 |
ef s="S": cdw sbp(.05,.45)circ_O; cdw sbp(.55,.95)circ_O; dw (fW,.3aH){up}..{up}(hP,.7aH); |
| 1075 |
ef s="F": dwh Z_q--Z_u; dwh (.1hP,.48aH)--(fW-hP,.48aH); dwv Z_b--Z_r; |
| 1076 |
ef s="P": dwv Z_b--Z_w; dw Z_r--(.65aW,fH){right}..(fW,.7aH)..{left}(.65aW,.44aH)..(hP,.44aH); |
| 1077 |
ef s="I": dwv Z_x--Z_s; dwh (hW-fP,hP)--(hW+fP,hP); dwh (hW-fP,fH)--(hW+fP,fH); |
| 1078 |
ef s="l": dwv Z_g--Z_f; dwh Z_s--Z_r; dwh Z_x--Z_z; |
| 1079 |
ef s="2": cdw (hP,1.3hP)..(.4fW,.35fH)..(fW,.65aH)..Z_s..(hP,.65aH); dwh Z_d--Z_a; |
| 1080 |
ef s="3": cdw sbp(0,.75)circ_Oh; cdw sbp(.25,.95)circ_sOh shifted (.2hP,hH-hP); |
| 1081 |
dwh (.3aW,hH)--(.7aW,hH); |
| 1082 |
ef s="4": dwh Z_j--Z_k; dwv Z_l--(0.75aW,aH)--(1.2hP,qH+hP); dwv (.75aW+qP,aH)--(1.7hP,qH+hP); |
| 1083 |
ef s="-": dwh Z_m--Z_o; |
| 1084 |
ef s="+": dwv Z_x--Z_s; dwh Z_m--Z_o; |
| 1085 |
ef s="A": dwvs(1.14)Z_b--Z_f--Z_e; dw .33[Z_b,Z_f]--.33[Z_e,Z_f]; |
| 1086 |
ef s="B": dw Z_r--Z_s{right}..(.85fH,.75aH)..{left}Z_y--Z_m--Z_y{right}..(.9fH,qH).. |
| 1087 |
{left}Z_x--Z_c; dwv Z_b--Z_w; |
| 1088 |
ef s="D": dw Z_r--Z_s..Z_o..Z_x--Z_c; dwv Z_b--Z_w; |
| 1089 |
ef s="E": pickup pensquare scaled fP; dw Z_z--Z_c--Z_r--Z_n; dw Z_m--Z_o; |
| 1090 |
ef s="G": cdw sbp(.06,.97)circ_O; dwh bot Z_y-- bot Z_v; |
| 1091 |
ef s="J": cdw Z_m..(hP,.4aH){down}..{right}Z_x{right}..{up}(fW,.4aH)..Z_t; |
| 1092 |
ef s="K": cdw Z_b--Z_w; cdw .35[.45[Z_b,Z_w],Z_u]--Z_e; cdw .35[Z_b,Z_w]--Z_u; |
| 1093 |
ef s="L": dwh Z_d--Z_a; dwv Z_b--Z_w; |
| 1094 |
ef s="M": dwv Z_b--Z_w; dwvs(1.14)Z_w--Z_x--Z_t; dwv Z_t--Z_e; |
| 1095 |
ef s="Q": dw circ_O; dw (.6aW,.4aH)--Z_e; |
| 1096 |
ef s="R": dwv Z_b--Z_w; dw Z_r--(.65aW,fH){right}..(fW,.7aH)..{left}(.65aW,.44aH)..(hP,.44aH); |
| 1097 |
cdw Z_e{up}..{left}(hW,.44aH); |
| 1098 |
ef s="T": dwh Z_q--Z_u; dwv .5[Z_q,Z_u]--Z_g; |
| 1099 |
ef s="U": cdw Z_w..Z_m{down}..{right}Z_x{right}..{up}Z_o..Z_t; |
| 1100 |
ef s="V": dwvs(1.2)Z_w--Z_g--Z_t; |
| 1101 |
ef s="W": dwvs(1.08)Z_w--(aW/4,0)--Z_f--Z_l--Z_t; |
| 1102 |
ef s="X": dwvs(1.4)Z_w..Z_e; dwvs(1.4) Z_b..Z_t; |
| 1103 |
ef s="Y": dwvs(1.2)Z_w--Z_y--Z_t; dwv Z_y--Z_g; |
| 1104 |
ef s="Z": dwh Z_q--Z_u; dwvs(1.4)(1.4hP,fP)--(aW-1.4hP,aH-fP); dwh Z_a--Z_d; |
| 1105 |
ef s="a": dw Z_x..Z_o..Z_s..Z_m..cycle; dwv Z_e--Z_t; |
| 1106 |
ef s="b": dw Z_x..Z_o..Z_p..Z_m..cycle; dwv Z_b--(hP,1.3aH) |
| 1107 |
ef s="c": cdw sbp(.06,.94)Z_o..Z_s..Z_m..Z_x..cycle; |
| 1108 |
ef s="d": dw Z_x..Z_o..Z_p..Z_m..cycle; dwv Z_e--(fW,1.3aH); |
| 1109 |
ef s="e": cdw sbp(0,.92)Z_o..Z_s..Z_m..Z_x..cycle; dw Z_o--Z_m; |
| 1110 |
ef s="f": cdw (.4fW,0)--(.4fW,.75aH){up}..(.75aW,fH)..{down}(fW,.8aH); dwh Z_h--Z_v; |
| 1111 |
ef s="g": dw circ_Oa; dw sbp(0,.5)circ_Oh shifted (0,-.5fH); cdw (fW,.7aH)--(fW,-qH); |
| 1112 |
ef s="h": cdw Z_b..(hP,.3aH){up}..(hW,.7fH)..{down}(fW,.3aH)..Z_e; dwv (hP,.3aH)--Z_w; |
| 1113 |
ef s="i": dwv Z_g--(hW,.7aH); ppcs 1.4fP; dw Z_s; |
| 1114 |
ef s="j": cdw (fW,.7aH)--Z_z..(aW/4,-.66fP)..Z_c; ppcs 1.4fP; dw Z_n; |
| 1115 |
ef s="k": dwv Z_b--(hP,1.3fH); cdw .5[Z_b,Z_w]--Z_e; cdw .5[Z_b,Z_w]--Z_u; |
| 1116 |
ef s="m": cdw Z_b..(hP,.3aH){up}..(.28aW,fH)..{down}(hW,.3aH)..Z_g; |
| 1117 |
cdw (hW,.6aH){up}..(.7aW,fH)..{down}(fW,.6aH)..Z_e; dwv (hP,.3aH)--Z_w; |
| 1118 |
ef s="n": cdw Z_b{up}..(hW,.8fH)..{down}Z_o..Z_e; dwv Z_b--(hP,.8aH); |
| 1119 |
ef s="o": dw Z_x..Z_o..Z_s..Z_m..cycle; |
| 1120 |
ef s="p": dw Z_x..Z_o..Z_s..Z_m..cycle; dwv Z_w--(hP,-.3aH); |
| 1121 |
ef s="q": dw Z_x..Z_o..Z_s..Z_m..cycle; dwv Z_t--(fW,-.3aH); |
| 1122 |
ef s="r": cdw (sbp(.35,.72)Z_x..Z_o..Z_s..Z_m..cycle) shifted(0,-1.5hP); dwv Z_b--Z_w; |
| 1123 |
ef s="s": cdw sbp(.05,.45)circ_O; cdw sbp(.55,.95)circ_O; dw (fW,.3aH){up}..{up}(hP,.7aH); |
| 1124 |
ef s="t": dwv Z_g--Z_f; dwh (0,.66aH)--(aW,.66aH); |
| 1125 |
ef s="u": cdw Z_w..(hP,.55aH){down}..Z_x..(fW,.55aH){up}..Z_t; dwv Z_t--Z_e; |
| 1126 |
ef s="v": dwv Z_w--Z_g--Z_t; |
| 1127 |
ef s="w": dwv Z_w--(aW/4,0)--Z_f--Z_l--Z_t; |
| 1128 |
ef s="x": dwvs(1.4)Z_w--Z_e; dwvs(1.4) Z_t--Z_b; |
| 1129 |
ef s="y": dwvs(1.4)(Z_w--Z_y) shifted (0,-.3aH); dwvs(1.4)(Z_t--Z_b) shifted (0,-.3aH); |
| 1130 |
ef s="z": dwh Z_q--Z_u; dwvs(1.4)(1.4hP,fP)--(aW-1.4hP,aH-fP); dwh Z_a--Z_d; |
| 1131 |
ef s="0": dw Z_m...Z_s...Z_o...Z_x...cycle; |
| 1132 |
ef s="1": dwv Z_g--(hW,aH-.3hP)--(hW-fP,aH-fP)--(hW-fP,aH-1.5fP); |
| 1133 |
ef s="5": dwh Z_q--Z_u-(hP,0); dwv Z_r--(hP,.55fH); |
| 1134 |
cdw (qP,.25aH)..(.65aW,1.3hP)..(fW,.4aH)..(hW,.63aH)..(.7hP,.56aH); |
| 1135 |
ef s="6": dw Z_x..(fW,.5fW)..Z_i..(hP,.5fW)..cycle; cdw (.8fP,hH)--Z_f; |
| 1136 |
ef s="7": dwh (0,.fH)--Z_u; dwvs(1.2)(aW-1.2hP,aH-fP)--(.4aW,0); |
| 1137 |
ef s="8": dw circ_Oh; dw (hP,.75aH)...Z_s...(fW,.75aH)...Z_y...cycle; |
| 1138 |
ef s="9": dw (Z_x..(fW,.5fW)..Z_i..(hP,.5fW)..cycle) shifted (0,.32aH); cdw (fW-.45fP,hH)--Z_g; |
| 1139 |
else: |
| 1140 |
fi |
| 1141 |
enddef; |
| 1142 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1143 |
def warn_valence(expr a)= |
| 1144 |
if addA[a]=0: |
| 1145 |
warning_s[incr warning_cnt]:="!Strange valence "&str_tbl[strA[a]]&"(A"&decimal a&") has"& |
| 1146 |
fdr(2)(bond_cntA)&" bonds"; |
| 1147 |
message "["&decimal fig_num&"]"&warning_s[warning_cnt]; message ""; fi |
| 1148 |
enddef; |
| 1149 |
%------------------------------------------------------------------------------------------------- |
| 1150 |
vardef erase_char(expr s)= |
| 1151 |
temps:=""; len_s:=length s; |
| 1152 |
if (len_s>=4)and(s<>"COOH"): |
| 1153 |
for i=1 upto len_s:tempc:=subc(s,i); if scan_c(tempc,"{}_^+")=0: temps:=temps&tempc; fi endfor |
| 1154 |
temps |
| 1155 |
else: s fi |
| 1156 |
enddef; |
| 1157 |
%------------------------------------------------------------------------------------------------- |
| 1158 |
vardef forbidden_to_underbar(expr s)= |
| 1159 |
temps:=""; len_s:=length s; |
| 1160 |
for i=1 upto len_s: |
| 1161 |
tempc:=subc(s,i); if scan_c(tempc,forbiddens)>0:temps:=temps&"_"; else:temps:=temps&tempc; fi |
| 1162 |
endfor temps |
| 1163 |
enddef; |
| 1164 |
%================================================================================================= |
| 1165 |
def proc_report_out= |
| 1166 |
file_output:=jobname&"-report.txt"; |
| 1167 |
block_cnt:=split_str(mc,",")(block_s); |
| 1168 |
puts "==========================================================================="; |
| 1169 |
puts " Fig["&decimal fig_num&"],Name["& EN&"],Category["&CAT&"],File["&file_input&"]"; |
| 1170 |
puts "---------------------------------------------------------------------------"; |
| 1171 |
puts " Row["&decimal mc_row&"],Length["&decimal length mc&"],Block"& |
| 1172 |
"["&decimal block_cnt&"]"&",BackboneA["&decimal backboneA&"]"& |
| 1173 |
",BackboneB["&decimal backboneB&"]"&",Group["&decimal grp_num&"]"; |
| 1174 |
puts "---------------------------------------------------------------------------"; |
| 1175 |
for i=1 upto mc_row: puts (substring(0,mc_indent[i]) of blanks)&mc[i]; endfor |
| 1176 |
puts "---------------------------------------------------------------------------"; |
| 1177 |
for i=1 upto block_cnt: puts "["&fdr(3)(i)&"] "&block_s[i]; endfor |
| 1178 |
puts "- error , warning ---------------------------------------------------------"; |
| 1179 |
for i=1 upto error_cnt: |
| 1180 |
puts error_s[error_e[i]]&" ["&decimal error_b[i]&"] "&block_s[error_b[i]]; |
| 1181 |
endfor |
| 1182 |
for i=1 upto warning_cnt: puts warning_s[i]; endfor |
| 1183 |
puts "---------------------------------------------------------------------------"; |
| 1184 |
puts " Width["&fdr(8)(mol_wd)&"],Height["&fdr(8)(mol_ht)&"],"& |
| 1185 |
" Shift x["& fdr(8)(minX)&"],Shift y["&fdr(8)(minY)&"]"; |
| 1186 |
puts " Bond length["&fdr(8)(blen)&"],Atom size["&fdr(8)(atom_wd)&"]"; |
| 1187 |
puts "---------------------------------------------------------------------------"; |
| 1188 |
puts " Atom["&decimal cntA&"],Bond["&decimal cntB& |
| 1189 |
"],Ring["&decimal(cntB-cntA+1)&"],Hide H["&decimal hideH_cnt&"]"; |
| 1190 |
puts "< NO. ><atom(s) >( x axis , y axis )<bond><hideH><chg>"; |
| 1191 |
for i=1 upto cntA: |
| 1192 |
puts " A"&fdl(6)(i)&fsl(8)(erase_char(str_tbl[strA[i]]))& |
| 1193 |
" ("&fdr(10)(round(xpart posA[i]/blen))&" , "& |
| 1194 |
fdr(10)(round(ypart posA[i]/blen))&" ) "&fdr(4)(Bcnt[i])& |
| 1195 |
iif(hideH[i]>0,fdr(6)(hideH[i])," ") if chargeA[i]<>0: &fdr(4)(chargeA[i]) fi; |
| 1196 |
endfor |
| 1197 |
puts "---------------------------------------------------------------------------"; |
| 1198 |
puts "< NO. >< bond (sdt)><angle +( +- )><length ( pt )>"; |
| 1199 |
for i=1 upto cntB: |
| 1200 |
nC:=lenB[i]; if nC=_size_atom: nC:=ratio_atom_bond; ef nC<0: nC:=-nC; fi |
| 1201 |
nB:=angB[i]; if nB>180: nB:=nB-360; fi |
| 1202 |
puts " B"&fdl(4)(i)&fdr(3)(sB[i])&" -> "&fdr(3)(eB[i])& |
| 1203 |
" ("&fdr(3)(bond_num[i])&")"&fdr(8)(round(angB[i]))& |
| 1204 |
" ("&fdr(6)(round(nB))&")"&fdr(8)(nC)&" ("&fdr(8)(round(nC*blen))&")"; |
| 1205 |
endfor |
| 1206 |
puts "---------------------------------------------------------------------------"; |
| 1207 |
puts "<atom>( atom wt )[ mi wt ] < cnt > < sum wt >[ sum mi wt ]"; |
| 1208 |
for i=1 upto tbl_atom_max: |
| 1209 |
if sumA[i]>=1: |
| 1210 |
puts " "&fsl(5)(erase_char(tbl_atoms[i]))& |
| 1211 |
"("&fdr(9)(tbl_atom_wt[i])&")"&"["&fdr(9)(tbl_atom_mi[i])&"]"&" * "&fdr(8)(sumA[i]) |
| 1212 |
&" "&fdr(7)(tbl_atom_wt[i]*sumA[i])&"["&fdr(12)(tbl_atom_mi[i]*sumA[i])&"]"; fi |
| 1213 |
endfor |
| 1214 |
puts " Molecular Weight [Mono Isotopic] = "&fsr(12)(mw)&"["&fsr(12)(MI)&"]"; |
| 1215 |
puts "---------------------------------------------------------------------------"; |
| 1216 |
puts " Weight Calc: "&mw if MW<>"-": &" - Input: "&MW&" = "&fdr(9)(MW_n-scantokens(MW)) fi; |
| 1217 |
puts " Fomula Calc: "&fm if FM<>"-": &" "&iif(fm=FM,"=","<>")&" Data: "&FM fi; |
| 1218 |
puts "==========================================================================="; |
| 1219 |
enddef; |
| 1220 |
%================================================================================================= |
| 1221 |
def proc_mol_out(expr n)= |
| 1222 |
if EN<>"-": EN_:=forbidden_to_underbar(EN); fi |
| 1223 |
%-V2000--------------------------------------------------------------------------------------- |
| 1224 |
if n=2000: |
| 1225 |
file_output:="m2k_"&fit_zero(fig_num)&"-"&EN_&".mol"; |
| 1226 |
puts ""; puts " -MCFtoMOL- "&fsl(20)(EN); puts ""; |
| 1227 |
puts fdr(3)(cntA)&fdr(3)(cntB)&" 0 0 0 0 0 0 0 0999 V2000"; |
| 1228 |
for i=1 upto cntA: |
| 1229 |
puts fdr(10)(xpart posA[i]/blen)& fdr(10)(ypart posA[i]/blen)&fdr(10)(0)&" "& |
| 1230 |
fsl(2)(erase_char(str_tbl[strA[i]]))&" 0"&fdr(3)(bond_charge(chargeA[i]))&" 0 0"; |
| 1231 |
endfor |
| 1232 |
for i=1 upto cntB: |
| 1233 |
if lineB[i]<>0: puts fdr(3)(sB[i])&fdr(3)(eB[i])&fdr(3)(bond_type(lineB[i]))& |
| 1234 |
fdr(3)(bond_stereo(lineB[i]))&" 0 0"; fi |
| 1235 |
endfor |
| 1236 |
puts "M END"; puts EOF; |
| 1237 |
%-V3000--------------------------------------------------------------------------------------- |
| 1238 |
ef n=3000: |
| 1239 |
file_output:="m3k_"&fit_zero(fig_num)&"-"&EN_&".mol"; |
| 1240 |
puts ""; puts " -MCFtoMOL- "&fsl(20)(EN); puts ""; |
| 1241 |
puts " 0 0 0 0 0 0 0 0 0 0 0 V3000"; |
| 1242 |
puts "M V30 BEGIN CTAB"; |
| 1243 |
puts "M V30 COUNTS "&decimal cntA&" "&decimal cntB&" 0 0 0"; |
| 1244 |
puts "M V30 BEGIN ATOM"; |
| 1245 |
for i=1 upto cntA: |
| 1246 |
puts "M V30 "&decimal i&" "&erase_char(str_tbl[strA[i]])&" "& |
| 1247 |
decimal(xpart posA[i]/blen)&" "&decimal(ypart posA[i]/blen)&" 0 0" |
| 1248 |
if chargeA[i]<>0: &" CHG="&decimal chargeA[i] fi; |
| 1249 |
endfor |
| 1250 |
puts "M V30 END ATOM"; puts "M V30 BEGIN BOND"; |
| 1251 |
for i=1 upto cntB: |
| 1252 |
if lineB[i]<>0: |
| 1253 |
puts "M V30 "&decimal i&" "&decimal bond_type(lineB[i])& |
| 1254 |
" "&decimal sB[i]&" "&decimal eB[i] |
| 1255 |
if bond_stereo(lineB[i])<>0: &" CFG="&decimal bond_config(lineB[i]) fi; fi |
| 1256 |
endfor |
| 1257 |
puts "M V30 END BOND"; puts "M V30 END CTAB"; puts "M END"; puts EOF; fi |
| 1258 |
enddef; |
| 1259 |
%================================================================================================= |
| 1260 |
def proc_mc_out= |
| 1261 |
file_output:="temp-mc.aux"; |
| 1262 |
if mc_length<100: |
| 1263 |
nB:=split_str(mc,",")(arg_s); nA:=0; temps:=""; |
| 1264 |
for i=1 upto nB: |
| 1265 |
if i=nB: temps:=temps&arg_s[i]; puts temps; |
| 1266 |
ef at_char[i+1]-nA>mc_length: nA:=at_char[i]; puts temps&arg_s[i]&","; temps:=""; |
| 1267 |
else: temps:=temps&arg_s[i]&","; fi |
| 1268 |
endfor |
| 1269 |
else: for i=1 upto mc_row: puts (substring(0,mc_indent[i]) of blanks)&mc[i]; endfor fi |
| 1270 |
puts EOF; |
| 1271 |
enddef; |
| 1272 |
%================================================================================================= |
| 1273 |
vardef fit_zero(expr n)= if n<=9: "00" ef n<=99: "0" else: "" fi &decimal n enddef; |
| 1274 |
vardef bond_type(expr n)= |
| 1275 |
if (n>=dl)and(n<=dm_):2 ef n=tm:3 ef (n=no)or(n=vf)or(n=vb): 0 else: 1 fi enddef; |
| 1276 |
vardef bond_charge(expr n)= if n=2: 1 ef n=1: 3 ef n=-1: 5 ef n=-2: 6 else: 0 fi enddef; |
| 1277 |
vardef bond_stereo(expr n)= |
| 1278 |
if (n=wf)or(n=zb)or(n=bd): 1 ef (n=zf)or(n=wb)or(n=dt): 6 ef n=wv: 4 else: 0 fi enddef; |
| 1279 |
vardef bond_config(expr n)= |
| 1280 |
if (n=wf)or(n=zb)or(n=bd): 1 ef (n=zf)or(n=wb)or(n=dt): 3 ef n=wv: 2 else: 0 fi enddef; |
| 1281 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1282 |
vardef define_atom(expr s,WT,MI)= |
| 1283 |
str_cnt:=str_cnt+1; tbl_cnt:=tbl_cnt+1; pc_num:=pc_num+1; |
| 1284 |
pc_x[pc_num][1]:=_set_atom; pc_y[pc_num][1]:=str_cnt; pc_cnt[pc_num]:=1; |
| 1285 |
str_tbl[str_cnt]:=tbl_atoms[tbl_cnt]:=s; tbl_atom[tbl_cnt]:=0; |
| 1286 |
tbl_atom_wt[tbl_cnt]:=WT; tbl_atom_mi[tbl_cnt]:=MI; pc_num |
| 1287 |
enddef; |
| 1288 |
%------------------------------------------------------------------------------------------------- |
| 1289 |
vardef define_grp_string(expr s)(text t)= |
| 1290 |
str_cnt:=str_cnt+1; tbl_cnt:=tbl_cnt+1; pc_num:=pc_num+1; |
| 1291 |
pc_x[pc_num][1]:=_set_atom; pc_y[pc_num][1]:=str_cnt; pc_cnt[pc_num]:=1; |
| 1292 |
str_tbl[str_cnt]:=tbl_atoms[tbl_cnt]:=s; tbl_atom[tbl_cnt]:=0; |
| 1293 |
for $=t: tbl_grp[tbl_cnt][incr tbl_atom[tbl_cnt]]:=$-pc_emb_start; endfor pc_num |
| 1294 |
enddef; |
| 1295 |
%================================================================================================= |
| 1296 |
def define_atom_grp_parts= |
| 1297 |
begingroup |
| 1298 |
save `,``,'; |
| 1299 |
def `=define_atom enddef; def ``=define_grp_string enddef; def '= define_parts enddef; |
| 1300 |
pc_int:=pc_emi_start; pc_num:=pc_emb_start; ?3:=?20:=Ph:=Ph1:=Ph2:=0; |
| 1301 |
%----------------------------------------------------------------------------------------------- |
| 1302 |
C= `("C" ,12.0107, 12.0000000); H= `("H" , 1.00794, 1.00782503223); |
| 1303 |
D= `("D" ,2.012, 2.01410177812); Ag=`("{Ag}",107.868, 106.905095); |
| 1304 |
Al=`("{Al}",26.9815, 26.98153853); As=`("{As}",74.9216, 74.92159457); |
| 1305 |
B= `("B" ,10.811, 11.00930536); Ba=`("{Ba}",137.33, 136.905816); |
| 1306 |
Be=`("{Be}",9.01218, 0); Bi=`("{Bi}",208.9804, 208.980338); |
| 1307 |
Br=`("{Br}",79.904, 78.9183376); Ca=`("{Ca}",40.078, 39.962590863); |
| 1308 |
Cd=`("{Cd}",112.41, 110.904182); Cl=`("{Cl}",35.453, 34.968852); |
| 1309 |
Co=`("{Co}",58.933194, 58.93319429); Cr=`("{Cr}",51.9961, 51.94050623); |
| 1310 |
Cs=`("{Cs}",132.905, 132.90543); Cu=`("{Cu}",63.546, 62.92959772); |
| 1311 |
F= `("F" ,18.9984, 18.99840316273); Fe=`("{Fe}",55.845, 55.93493633); |
| 1312 |
Hg=`("{Hg}",200.59, 201.97064340); I= `("I" ,126.90447,126.9044719); |
| 1313 |
K= `("K" ,39.0983, 38.9637064864); Li=`("{Li}",6.941, 7.0160034366); |
| 1314 |
Mg=`("{Mg}",24.305, 23.985041697); Mn=`("{Mn}",54.938044, 54.93804391); |
| 1315 |
Mo=`("{Mo}",95.95, 0); N= `("N" ,14.0067, 14.00307400443); |
| 1316 |
Na=`("{Na}",22.98977, 22.9897692820); Ni=`("{Ni}",58.693, 57.93534241); |
| 1317 |
O= `("O" ,15.9994, 15.99491461957); P= `("P" ,30.973762, 30.97376199842); |
| 1318 |
Pb=`("{Pb}",207.2, 205.974455); Pd=`("{Pd}",106.4, 107.905075); |
| 1319 |
S= `("S" ,32.065, 31.9720711744); Sb=`("{Sb}",121.75, 120.90381); |
| 1320 |
Se=`("{Se}",78.971, 79.9165218); Si=`("{Si}",28.0855, 27.97692653465); |
| 1321 |
Sn=`("{Sn}",118.71, 119.90220163); Ta=`("{Ta}",180.948, 0); |
| 1322 |
Te=`("{Te}",127.60, 129.90623); Ti=`("{Ti}",47.867, 47.94794198); |
| 1323 |
U= `("U", 238.0289, 238.05079); V= `("V", 50.9415, 50.943957); |
| 1324 |
W= `("W", 183.85, 181.948225); Zn=`("{Zn}",65.409, 63.92914201); |
| 1325 |
NO_ATOM=`("",0,0); |
| 1326 |
tbl_atom_end:=tbl_cnt; |
| 1327 |
%----------------------------------------------------------------------------------------------- |
| 1328 |
if f_expand=0: |
| 1329 |
CH3=``("C{H_3_}")(C,H,H,H); CH2=``("C{H_3_}")(C,H,H); CN=``("CN")(C,N); OH=``("OH")(O,H); |
| 1330 |
COOH=``("COOH")(C,O,O,H); COONa=``("COO{Na}")(C,O,O,Na); CHO=``("CHO")(C,H,O); |
| 1331 |
NO=``("NO")(N,O); NO2=``("N{O_2_}")(N,O,O); NH2=``("N{H_2_}")(N,H,H); SH=``("SH")(S,H); |
| 1332 |
SO2H=``("S{O_2_}H")(S,O,O,H); SO3H=``("S{O_3_}H")(S,O,O,O,H); ONa=``("O{Na}")(O,Na); |
| 1333 |
SO3Na:=``("S{O_3_}{Na}")(S,O,O,O,Na); fi |
| 1334 |
%----------------------------------------------------------------------------------------------- |
| 1335 |
tbl_grp_end:=tbl_cnt; pc_atm_end:=pc_num; |
| 1336 |
if f_expand=1: |
| 1337 |
NH:='(N,/H); CH3:='(/H,/H^60,/H^-60); NH2:='(N,/H^60,/H^-60); NO2:='(N,//O^60,//O^-60); |
| 1338 |
OH:='(O,/H); NO:='(N,//O); SH:='(S,/H); SO2H:='(S,//O^60,/OH^-60); |
| 1339 |
SO3H:='(S,//O^90,//O^-90,/OH); CHO:='(//O^-60,/H^60); COOH:='(//O^-60,/OH^60); |
| 1340 |
CN:='(/N~tm); ONa:='(O,/Na); SO3Na:='(S,//O^90,//O^-90,/Na); COONa:='(//O,60,O,-60,Na); |
| 1341 |
else: NH:='(N,/H~~nl); fi |
| 1342 |
%----------------------------------------------------------------------------------------------- |
| 1343 |
!:=!1:='((_mk_bond,_auto_ang)); ?:='(/NO_ATOM); ?wf:=?w:='(*/NO_ATOM); ?zf:=?z:='(/*NO_ATOM); |
| 1344 |
?S:='(//S); ?O:='(//O); ?NH:='(//NH); ?H:='(/H); ?F:='(/F); ?OH:='(/OH); ?OH:='(/COOH); |
| 1345 |
?NH2:='(/NH2); ?Cl:='(/Cl); ?2:='(/!); ?dm:=?d:='((_grp_dm,NO_ATOM)); |
| 1346 |
for i=3 upto 20: ?[i]:='((_set_len,_ring),^~((-180 DIV i)-90) for j=2 upto i:,360 DIV i endfor |
| 1347 |
,(_cyc_sB,1-i),(_set_len,_end)); endfor |
| 1348 |
for i=2 upto 20: ![i]:='((_set_len,_chain),! for j=2 upto i:,! endfor ,(_set_len,_end)); endfor |
| 1349 |
Ph:=Ph1:='(?6,-2==dl,-4==dl,-6==dl); Ph2:='(?6,-1==dl,-3==dl,-5==dl); |
| 1350 |
!db:=!d:='(!~db); !tm:=!t:='(!~tm); !wf:=!w:='(!~wf); !zf:=!z:='(!~zf); !wb:='(!~wb); |
| 1351 |
!zb:='(!~zb); !dl:='(!~dl); !dr:='(!~dr); !dm:='(!~dm); !d!:='(!~db,!); !!d:='(!,!db); |
| 1352 |
!!d!:='(!,!db,!); ?!:='(?,!); !?:='(!,?); ?!d:='(?,!d); ?!2:='(?,!2); ??!:='(?,?^60,60); |
| 1353 |
??:='(?^35,?^-35); !?!:='(!?,!); !??!:='(!,??,!); !??:='(!,??); !?2:='(!,?2); ?2!:='(?2,!); |
| 1354 |
|> :='((_com,_mark)); <| :='((_com,_moff)); =| :='((_chg_len,_end)); |
| 1355 |
?F!F:='(/F,60,F); ?F?F!F:='(/F,/F^60,60,F); ?Br!Br:='(/Br,60,Br); ?Cl!Cl:='(/Cl,60,Cl); |
| 1356 |
?Cl?Cl!Cl:='(/Cl,/Cl^60,60,Cl); |
| 1357 |
N!:='(N,!); N?:='(N,?); N!2:='(N,!3); N!2:='(N,!3); !N:='(!,N); N?!:='(N,?!); N?2:='(N,?2); |
| 1358 |
S?O:='(S,?O); S?O!:='(S?O,!); ?O?O:='(?O^-35,?O^35); S?O?O:='(S,?O?O); S?O?O!:='(S?O?O,!); |
| 1359 |
O!:='(O,!); O!2:='(O,!2); O!3:='(O,!3); S!:='(S,!); S!2:='(S,!2); S!3:='(S,!3); !S:='(!,S); |
| 1360 |
?O!:='(?O,!); ?O!2:='(?O,!2); ?O!3:='(?O,!3); !?O:='(!,?O); !?O!:='(!,?O!); ?O!O:='(?O,!,O); |
| 1361 |
NH!:='(NH,!); NH!2:='(NH,!2); !NH:='(!,NH); !NH!:='(!,NH!); |
| 1362 |
!OH:='(!,OH); !SH:='(!,SH); !NH2:='(!,NH2); !S?O:='(!,S?O); !O:='(!,O); !dO:='(!d,O); |
| 1363 |
!Cl:='(!,Cl); !Br:='(!,Br); !F:='(!,F); !O!:='(!,O!); !S!:='(!,S!); |
| 1364 |
!COOH:='(!,COOH); ?COOH:='(/COOH); !CH3:='(!,CH3); !CN:='(!,CN); !CHO:='(!,CHO); !NO2:='(!,NO2); |
| 1365 |
!?3:='(!,?3); !?4:='(!,?4); !?5:='(!,?5); !?6:='(!,?6); !?7:='(!,?7); !?8:='(!,?8); |
| 1366 |
!Ph:='(!,Ph); !?OH:='(!,?OH); ?OH!:='(?OH,!); |
| 1367 |
n_:='((_add_charge,MIS)); p_:='((_add_charge,PLS)); |
| 1368 |
hexose_hp:='(`'1.4,-30~wf_r,30~bd_r`1,30~wb_r,120,O,30,<:1,reset_len); |
| 1369 |
Pyranose_hp:='(`'1.4,-35~wf_r,35~bd_r`1,30~wb_r,130`1.66,O,<:1,reset_len); |
| 1370 |
endgroup |
| 1371 |
enddef; |
| 1372 |
%------------------------------------------------------------------------------------------------- |
| 1373 |
define_atom_grp_parts; |
| 1374 |
store_restore_par(0)(parameter_list); |
| 1375 |
for i=pc_emb_start+1 upto pc_num: pc_all:=pc_all+pc_cnt[i]; endfor |
| 1376 |
message "pc_emb="&decimal pc_emb_start&" => "&decimal pc_num&" [ "&decimal pc_all&" ]"; |
| 1377 |
message "pc_emi="&decimal pc_emi_start&" => "&decimal pc_int; |
| 1378 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1379 |
def loadm(text t)= |
| 1380 |
begingroup |
| 1381 |
save f_mcf,unit_cnt,row_s,row_cnt,info_cnt,order,min_n,max_n,sign_at,sign_n,tag_s,line_cnt, |
| 1382 |
val_s,filter_n,filter_tag,filter_val,filter_sign,filter_cnt,filter_p,lib_unit_cnt,at_colon, |
| 1383 |
at_equal,at_less,at_greater,at_n,sort_tbl,key_s,sort_s,sign_s,sV,sT,header_s,sort_oder, |
| 1384 |
opt_cnt; |
| 1385 |
string row_s[][],sort_tbl[],key_s,filter_tag[],filter_val[],sign_s[],tag_s[][],val_s[][],sort_s, |
| 1386 |
header_s,sV,sT; |
| 1387 |
numeric row_cnt[],order[],order_tbl[],filter_sign[],filter_p[]; |
| 1388 |
line_cnt:=f_mcf:=mc_row:=info_cnt:=filter_cnt:=lib_unit_cnt:=0; unit_cnt:=1; file_input:=libm; |
| 1389 |
sign_s1:="="; sign_s2:="<>"; sign_s3:="<"; sign_s4:=">"; sign_s5:="<="; sign_s6:=">="; |
| 1390 |
header_s:=""; key_s:=""; |
| 1391 |
%--------------------------------------------------------------------------------------------- |
| 1392 |
opt_cnt:=0; for $=t: opt_cnt:=opt_cnt+1; endfor |
| 1393 |
if opt_cnt=0: filter_cnt:=1; filter_sign[1]=2; filter_tag[1]:="LV"; filter_val[1]:="-"; |
| 1394 |
else: |
| 1395 |
for $=t: |
| 1396 |
at_colon:=scan_c(":",$); at_equal:=scan_c("=",$); at_less:=scan_c("<",$); |
| 1397 |
at_greater:=scan_c(">",$); key_s:=sT:=sV:=""; sign_n:=sign_at:=at_n:=0; |
| 1398 |
if at_colon>=2: sign_at:=at_colon; sign_n:=7; at_n:=1; |
| 1399 |
ef at_equal>=2: if (at_equal-1)=at_less: sign_at:=at_equal; sign_n:=5; at_n:=2; |
| 1400 |
ef (at_equal-1)=at_greater: sign_at:=at_equal; sign_n:=6; at_n:=2; |
| 1401 |
else: sign_at:=at_equal; sign_n:=1; at_n:=1; fi |
| 1402 |
ef at_greater>=2: if (at_greater-1)=at_less: sign_at:=at_greater; sign_n:=2; at_n:=2; |
| 1403 |
else: sign_at:=at_greater; sign_n:=4; at_n:=1; fi |
| 1404 |
ef at_less>=2: sign_at:=at_less; sign_n:=3; at_n:=1; fi |
| 1405 |
if sign_at>=1: sT:=substring(0,sign_at-at_n)of $; sV:=substring(sign_at,length $)of $; fi |
| 1406 |
if sign_n=0: if scan_c(".",$)=0: file_input:=$&".mcf"; else: file_input:=$; fi |
| 1407 |
filter_cnt:=1; filter_sign[1]=2; filter_tag[1]:="LV"; filter_val[1]:="-"; |
| 1408 |
ef sign_n=7: if sT="a": key_s:=sV; sort_oder:=0; ef sT="d": key_s:=sV; sort_oder:=1; fi |
| 1409 |
else: |
| 1410 |
filter_tag[incr filter_cnt]:=sT; filter_sign[filter_cnt]:=sign_n; |
| 1411 |
if is_num sV: filter_val[filter_cnt]:=fix_num sV; else: filter_val[filter_cnt]:=sV; fi |
| 1412 |
fi |
| 1413 |
endfor |
| 1414 |
fi |
| 1415 |
%-------------------------------------------------------------------------------------------- |
| 1416 |
forever: |
| 1417 |
lines:=readfrom file_input; exitif lines=EOF; tempc:=substring (0,1) of lines; |
| 1418 |
if tempc<>"%": |
| 1419 |
row_s[unit_cnt][incr line_cnt]:=lines; |
| 1420 |
if tempc=";": |
| 1421 |
row_cnt[unit_cnt]:=line_cnt; f_mcf:=line_cnt:=0; filter_n:=1; sort_s:=""; |
| 1422 |
for i=1 upto filter_cnt: filter_p[i]:=0; endfor |
| 1423 |
for i=1 upto info_cnt: |
| 1424 |
get_tag_var(arg_s[i])(sT,sV); tag_s[unit_cnt][i]:=sT; val_s[unit_cnt][i]:=sV; |
| 1425 |
if sT=key_s: if is_num sV: sort_s:=fix_num sV; else: sort_s:=sV; fi fi |
| 1426 |
for j=1 upto filter_cnt: |
| 1427 |
if filter_tag[j]=sT: |
| 1428 |
filter_p[j]:=1; if is_num sV: temps:=fix_num sV; else: temps:=sV; fi |
| 1429 |
if filter_sign[j]=1: if not(temps= filter_val[j]): filter_n:=0; fi |
| 1430 |
ef filter_sign[j]=2: if not(temps<>filter_val[j]): filter_n:=0; fi |
| 1431 |
ef filter_sign[j]=3: if not(temps< filter_val[j]): filter_n:=0; fi |
| 1432 |
ef filter_sign[j]=4: if not(temps> filter_val[j]): filter_n:=0; fi |
| 1433 |
ef filter_sign[j]=5: if not(temps<=filter_val[j]): filter_n:=0; fi |
| 1434 |
ef filter_sign[j]=6: if not(temps>=filter_val[j]): filter_n:=0; fi fi |
| 1435 |
fi |
| 1436 |
endfor |
| 1437 |
endfor |
| 1438 |
for i=1 upto filter_cnt: if filter_p[i]=0: filter_n:=0; fi endfor |
| 1439 |
info_cnt:=0; lib_unit_cnt:=lib_unit_cnt+1; |
| 1440 |
if filter_n=1: if key_s<>"": sort_tbl[unit_cnt]:=sort_s; fi unit_cnt:=unit_cnt+1; fi |
| 1441 |
ef tempc=":": f_mcf:=mc_row:=1; |
| 1442 |
unit_info[unit_cnt]:=info_cnt:=split_str(header_s,";")(arg_s); header_s:=""; |
| 1443 |
ef tempc<>"%": if f_mcf=1: mc_row:=mc_row+1; |
| 1444 |
else: if header_s="": header_s:=lines; else: header_s:=header_s&lines; fi fi |
| 1445 |
fi |
| 1446 |
fi |
| 1447 |
endfor |
| 1448 |
ucount:=unit_cnt:=unit_cnt-1; |
| 1449 |
%---------------------------------------------------------------------------------------------- |
| 1450 |
message "* Input : "&file_input&" ["&decimal lib_unit_cnt&"]"; |
| 1451 |
message "* Output : ucount ["&decimal ucount&"]"; message ""; |
| 1452 |
for i=1 upto filter_cnt: |
| 1453 |
message "* Filter("&decimal i&"): "&filter_tag[i]&" "&sign_s[filter_sign[i]]&filter_val[i]; |
| 1454 |
endfor |
| 1455 |
if key_s<>"": message "* Sort key : "&key_s&iif(sort_oder=0," (ascending)"," (descending)"); fi |
| 1456 |
if key_s<>"": |
| 1457 |
for i=1 upto unit_cnt: order[i]:=0; endfor |
| 1458 |
for i=1 upto unit_cnt: |
| 1459 |
if sort_oder=0: temps:="~"; |
| 1460 |
for j=1 upto unit_cnt: |
| 1461 |
if order[j]=0: if sort_tbl[j]<temps: temps:=sort_tbl[j]; min_n:=j; fi fi |
| 1462 |
endfor |
| 1463 |
order[min_n]:=i; order_tbl[i]:=min_n; |
| 1464 |
ef sort_oder=1: temps:=" "; |
| 1465 |
for j=1 upto unit_cnt: |
| 1466 |
if order[j]=0: if sort_tbl[j]>temps: temps:=sort_tbl[j]; max_n:=j; fi fi |
| 1467 |
endfor |
| 1468 |
order[max_n]:=i; order_tbl[i]:=max_n; fi |
| 1469 |
endfor |
| 1470 |
for i=1 upto unit_cnt: |
| 1471 |
for j=1 upto unit_info[order_tbl[i]]: |
| 1472 |
lib_tag[i][j]:=tag_s[order_tbl[i]][j]; lib_val[i][j]:=val_s[order_tbl[i]][j]; |
| 1473 |
endfor |
| 1474 |
unit_lines[i]:=row_cnt[order_tbl[i]]; |
| 1475 |
for j=1 upto row_cnt[order_tbl[i]]: row[i][j]:=row_s[order_tbl[i]][j]; endfor |
| 1476 |
endfor |
| 1477 |
else: |
| 1478 |
for i=1 upto unit_cnt: |
| 1479 |
for j=1 upto unit_info[i]: lib_tag[i][j]:=tag_s[i][j]; lib_val[i][j]:=val_s[i][j]; endfor |
| 1480 |
unit_lines[i]:=row_cnt[i]; for j=1 upto row_cnt[i]: row[i][j]:=row_s[i][j]; endfor |
| 1481 |
endfor |
| 1482 |
fi |
| 1483 |
closefrom file_input; |
| 1484 |
endgroup; % [;] |
| 1485 |
enddef; |
| 1486 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1487 |
vardef fix_num expr s= |
| 1488 |
ts:=s; nN:=scan_c(".",ts); |
| 1489 |
if nN=0: ts:=fsr(4)(ts); ef nN=1: ts:=" 0"&ts; ef nN=2: ts:=" "&ts; |
| 1490 |
ef nN=3: ts:=" "&ts; ef nN=4: ts:=" "&ts; fi ts |
| 1491 |
enddef; |
| 1492 |
vardef scan_bit(expr n,b)= if b>=1: odd floor(n/b) else: odd floor((n-floor n)/b) fi enddef; |
| 1493 |
vardef scan_c(expr c,s)= |
| 1494 |
nN:=0; nA:=length s; for i=1 upto nA: if subc(s,i)=c: nN:=i; fi exitif nN>0; endfor nN |
| 1495 |
enddef; |
| 1496 |
vardef is_num expr s= |
| 1497 |
for i=1 upto length s: tc:=subc(s,i); bA:=((tc>="0")and(tc<="9"))or(tc="."); exitif not bA; |
| 1498 |
endfor bA |
| 1499 |
enddef; |
| 1500 |
vardef is_char(expr c,s)= |
| 1501 |
nN:=0; for i=1 upto length s: tc:=subc(s,i); nN:=scan_c(tc,c); exitif nN>0; endfor nN |
| 1502 |
enddef; |
| 1503 |
vardef match_paren(expr s)= |
| 1504 |
nA:=0; |
| 1505 |
for i=1 upto length s: tc:=subc(s,i); if tc="(": nA:=nA+1; ef tc=")": nA:=nA-1; fi endfor nA |
| 1506 |
enddef; |
| 1507 |
vardef split_str(expr s,c)(suffix v)= |
| 1508 |
at_char[0]:=nN:=0; nA:=length s; |
| 1509 |
for i=1 upto nA: if subc(s,i)=c: at_char[incr nN]:=i; fi endfor at_char[incr nN]:=nA+1; |
| 1510 |
for i=1 upto nN: v[i]:=substring (at_char[i-1],at_char[i]-1) of s; endfor nN |
| 1511 |
enddef; |
| 1512 |
vardef get_tag_var(expr s)(suffix t,v)= |
| 1513 |
nN:=scan_c(":",s); t:=substring(0,nN-1) of s; v:=substring(nN,length s) of s; |
| 1514 |
enddef; |
| 1515 |
vardef erase_blank expr s= |
| 1516 |
nN:=length s; |
| 1517 |
for i=1 upto nN: nA:=i; exitif subc(s,i)<>" "; endfor |
| 1518 |
for i=nN downto 1: nB:=i; exitif subc(s,i)<>" "; endfor |
| 1519 |
ts:=substring(nA-1,nB) of s; ts enddef; |
| 1520 |
def allm= for i=1 upto ucount: beginfigm getm(i) putm endfigm endfor enddef; |
| 1521 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |