From bdca005b9c5b680e145fec55ef1186f1092a4639 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Sat, 15 Oct 2016 22:51:08 +0000 Subject: mcf2graph (15oct16) git-svn-id: svn://tug.org/texlive/trunk@42264 c570f23f-e606-0410-a88d-b1316a301751 --- Master/texmf-dist/metapost/mcf2graph/mcf2graph.mf | 186 ++++++++++------------ 1 file changed, 83 insertions(+), 103 deletions(-) (limited to 'Master/texmf-dist/metapost/mcf2graph') diff --git a/Master/texmf-dist/metapost/mcf2graph/mcf2graph.mf b/Master/texmf-dist/metapost/mcf2graph/mcf2graph.mf index bca5145d9b3..10fdeaad35a 100644 --- a/Master/texmf-dist/metapost/mcf2graph/mcf2graph.mf +++ b/Master/texmf-dist/metapost/mcf2graph/mcf2graph.mf @@ -1,5 +1,5 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% mcf2graph ver 3.98 Copyright (c) 2013-2016 Akira Yamaji +% mcf2graph ver 3.99 Copyright (c) 2013-2016 Akira Yamaji % % Permission is hereby granted, free of charge, to any person obtaining a copy of this software % and associated documentation files (the "Software"), to deal in the Software without restriction, @@ -30,7 +30,7 @@ % Set output checklist : mpost -s ahlength=2 FILENAME %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% tracingstats:=1; -message " This is mcf2graph ver 4.0 2016.10"; +message " This is mcf2graph ver 3.9 2016.10"; %------------------------------------------------------------------------------------------------- pair posB[],posA[],pairT,Ls,Le,pairA; numeric angB[],angA[],br_ang[],sB[],eB[],f_FON[],atom_w[],atom_h[],atom_d[],strA[],stkB[],stkA[], @@ -60,7 +60,7 @@ if known green: f_MP:=1; elseif ahangle=3: sw_MOLout:=1; def shipit = enddef; % MDL Molefile on fi outputtemplate:="%j-%3c."&outputformat; - def beginchar(text s)= beginfig(char_num) enddef; + def beginchar(expr a,b,c,d)= beginfig(char_num) w:=b*pt; h:=c*pt; enddef; def endchar = endfig enddef; def printf expr s= write s to mp_log_name enddef; def # = enddef; @@ -97,76 +97,80 @@ def parameter_list= sw_checklist,sw_numberA,sw_numberB,sw_mol_frame,sw_auxout,sw_solid,sw_expand,sw_MOLout, sw_start_vector,sw_atom_frame,sw_font_frame,sw_subst_off,sw_bond_single,sw_clip, margin_left_right,margin_top_bottom,ratio_atom_bond,ratio_thickness_bond,ratio_char_bond, - ratio_chain_ring,offset_atom#,max_bond_width,ratio_bondgap_bond,ratio_zebra_black, - ratio_zebragap_bond,ratio_wedge_bond,ratio_atomgap_atom,bond_len#, - offset_wedge#,max_bond_length#,offset_zebra_gap#,offset_bond_gap#,thickness_font_frame#, - offset_thickness#,numberA_start,numberA_end,numberB_start,numberB_end + ratio_chain_ring,max_bond_width,ratio_bondgap_bond,ratio_zebra_black,ratio_zebragap_bond, + ratio_wedge_bond,ratio_atomgap_atom,bond_len#,offset_atom#,offset_wedge#,max_bond_length#, + offset_zebra_gap#,offset_bond_gap#,thickness_font_frame#,offset_thickness#, + numberA_start,numberA_end,numberB_start,numberB_end enddef; %------------------------------------------------------------------------------------------------- nA:=0; for list=parameter_list: stock_p[incr nA]:=list; endfor def store_par(text t)= nA:=0; for list=t: if stock_p[incr nA]<>list: stock_p[nA]:=list; fi endfor enddef; def restore_par(text t)= nA:=0; - forsuffixes list=t: if list<>stock_p[incr nA]: list:=stock_p[nA]; fi endfor -enddef; + forsuffixes list=t: if list<>stock_p[incr nA]: list:=stock_p[nA]; fi endfor enddef; %------------------------------------------------------------------------------------------------- def beginfont(text s)= inf_EN:=inf_JN:=inf_FM:=inf_CAS:=inf_USE:=inf_EXA:=inf_EXB:=""; inf_MW:="0"; len_x:=len_y:=cntA:=inf_num:=f_beginchar:=0; - store_par(parameter_list); save_wd#:=font_wd#; save_ht#:=font_ht#; - ratio_bond_width:=0.025; - clearit; + store_par(parameter_list); + save_wd#:=font_wd#; save_ht#:=font_ht#; for list=s: inf_num:=inf_num+1; info[inf_num]:=list; nA:=0; for i=0 upto length(list): if pic_c(i,list)=":": nA:=i; fi exitif nA>0; endfor if nA>0: s_tag:=substring (0,nA) of list; s_var:=substring (nA+1,length(list)) of list; - if s_tag="NO": inf_NO:=s_var; elseif s_tag="MW": inf_MW:=s_var; - elseif s_tag="EN": inf_EN:=s_var; elseif s_tag="JN": inf_JN:=s_var; + if s_tag="NO": inf_NO:=s_var; elseif s_tag="MW": inf_MW:=s_var; + elseif s_tag="EN": inf_EN:=s_var; elseif s_tag="JN": inf_JN:=s_var; elseif s_tag="FM": inf_FM:=s_var; elseif s_tag="CAS": inf_CAS:=s_var; elseif s_tag="USE": inf_USE:=s_var; elseif s_tag="EXA": inf_EXA:=s_var; - elseif s_tag="EXB": inf_EXB:=s_var; - fi + elseif s_tag="EXB": inf_EXB:=s_var; fi fi endfor + clearit; enddef; %------------------------------------------------------------------------------------------------- def endfont= - if (sw_font_frame=1)or(sw_font_frame=3): - AUX(0,0)(draw_frame(font_wd,font_ht,(0,0),thickness_font_frame);) fi + if (sw_font_frame=1)or(sw_font_frame=3): + AUX(0,0)(draw_frame(w,h,(0,0),thickness_font_frame);) fi if (sw_font_frame=2)or(sw_font_frame=3): - AUX(0,0)(draw_frame(font_wd-2margin_left_right,font_ht-2margin_top_bottom, + AUX(0,0)(draw_frame(w-2margin_left_right,h-2margin_top_bottom, (margin_left_right,margin_top_bottom),thickness_font_frame);) fi - if sw_font_frame=4: AUX(0,0)(draw_corner(font_wd,font_ht,thickness_font_frame);) fi + if sw_font_frame=4: AUX(0,0)(draw_corner(w,h,thickness_font_frame);) fi if (sw_auxout=1)or(sw_checklist=1)or(sw_MOLout=1): mol_check; fi if sw_auxout=1: auxfile_out; fi if sw_checklist=1: checklist_out; fi if sw_MOLout=1: MOLfileout; fi - if f_beginchar=1: - char_num:=char_num+1; currentpicture:=chem_structure; chem_structure:=nullpicture; - endchar; fi + char_num:=char_num+1; currentpicture:=chem_structure; chem_structure:=nullpicture; endchar; restore_par(parameter_list); font_wd#:=save_wd#; font_ht#:=save_ht#; if proc_end=1: scantokens("bye"); fi enddef; %------------------------------------------------------------------------------------------------- -def size_setup= - if sw_solid=0: bond_len#:=font_wd#*ratio_bond_width; fi - wedge_wd# := ratio_wedge_bond*bond_len#+offset_wedge#; - zebra_gap# := ratio_zebragap_bond*bond_len#+offset_zebra_gap#; - if (ratio_atom_bond*bond_len#+offset_atom#)<.8bond_len#: - atom_wd#:=ratio_atom_bond*bond_len#+offset_atom#; - else: - atom_wd#:=.8bond_len#; ratio_chain_ring:= .5; - fi - gap#:= ratio_bondgap_bond*bond_len#+offset_bond_gap#; - bond_pen_wd# := ratio_thickness_bond*bond_len#+offset_thickness#; - char_pen_wd# := ratio_char_bond*bond_pen_wd#; - define_pixels(bond_len,zebra_gap,wedge_wd,atom_wd,gap,bond_pen_wd,char_pen_wd, - font_wd,font_ht,thickness_font_frame); - font_size_setup; +def char_size_set(expr a)(expr b)(expr c)(expr s)= + for j=0 upto length(s)-1: nA:=ASCII(pic_c(j,s)); + if f_FON[nA]=1: atom_w[nA]#:=atom_wd#*a; atom_h[nA]#:=atom_wd#*b; atom_d[nA]#:=atom_wd#*c; + define_pixels(atom_w[nA],atom_h[nA],atom_d[nA]); fi + endfor enddef; %------------------------------------------------------------------------------------------------- -def scaling= +def mol_size_setup= + if (bond_len#*ratio_atom_bond+offset_atom#)<.8bond_len#: + atom_wd#:=bond_len#*ratio_atom_bond+offset_atom#; + else: atom_wd#:=.8bond_len#; ratio_chain_ring:= .5; fi + wedge_wd#:= bond_len#*ratio_wedge_bond+offset_wedge#; + zebra_gap#:= bond_len#*ratio_zebragap_bond+offset_zebra_gap#; + bondgap#:= bond_len#*ratio_bondgap_bond+offset_bond_gap#; + bond_pen_wd#:= bond_len#*ratio_thickness_bond+offset_thickness#; + char_pen_wd#:= bond_pen_wd#*ratio_char_bond; + define_pixels(bond_len,zebra_gap,wedge_wd,atom_wd,bondgap,bond_pen_wd,char_pen_wd); + char_size_set( 1)( 1)( 0)("CGHMNOQ"); + char_size_set(.9)( 1)( 0)("ABDEFIJKLPRSTUVWXYZ-+/>0: str_len:=nC:=num_d:=0; @@ -189,18 +193,13 @@ for i=1 upto cntA: xpos:=xpart(posA[i]); ypos:=ypart(posA[i]); len_x:=max_x-min_x; len_y:=max_y-min_y; enddef; %------------------------------------------------------------------------------------------------- -def resize(expr WD,HT)= - if (len_y/len_x)>(font_ht/font_wd): - factor:=(font_ht*HT-2margin_top_bottom)/len_y; - else: - factor:=(font_wd*WD-2margin_left_right)/len_x; - fi - ratio_bond_width:=ratio_bond_width*factor; - len_x:=len_x*factor; len_y:=len_y*factor; +def mol_resize(expr WD,HT)= + if (len_y/len_x)>(font_ht/font_wd): factor:=(font_ht*HT-2margin_top_bottom)/len_y; + else: factor:=(font_wd*WD-2margin_left_right)/len_x; fi enddef; %------------------------------------------------------------------------------------------------- for i=1 upto 128: f_FON[i]:=0; endfor asc0:=ASCII("0"); asc9:=ASCII("9"); -def font_use_check= +def char_use_check= for i=1 upto 128: if f_FON[i]<>0: f_FON[i]:=0; fi endfor if (sw_numberA>=1)or(sw_numberB>=1): for j=asc0 upto asc9: f_FON[j]:=1; endfor else: for i=1 upto cntA: if strA[i]<>0: for j=0 upto length(com_str[strA[i]])-1: @@ -384,32 +383,25 @@ def MCd(expr RW,RH)(expr FW,FH)(text s)= if (sw_expand=1)or(sw_MOLout=1): expand_set; fi ''(0)(s,(_term,0)); proc_bond_atom(1); cntA_skeleton:=cntA; cntB_skeleton:=cntB; if cntP>0: ps_get(1); fi - font_use_check; - if sw_solid>=1: - size_setup; proc_skeleton; scaling; + define_pixels(font_wd,font_ht,thickness_font_frame); + char_use_check; + if sw_solid>=1: mol_size_setup; proc_skeleton; mol_scaling; else: - size_setup; proc_skeleton; scaling; resize(RW,RH); size_setup; + bond_len#:=0.025font_wd#; mol_size_setup; + for i=1 upto 6: + proc_skeleton; mol_scaling; mol_resize(RW,RH); exitif factor=1; + bond_len#:=bond_len#*factor; mol_size_setup; + endfor if bond_len#>max_bond_length#: - sw_solid:=1; bond_len#:=max_bond_length#; - size_setup; proc_skeleton; scaling; sw_solid:=0; - else: - for i=1 upto 4: proc_skeleton; scaling; resize(RW,RH); size_setup; endfor - fi + bond_len#:=max_bond_length#; mol_size_setup; proc_skeleton; mol_scaling; fi fi - font_setup; + char_font_setup; if sw_subst_off=1: cntA:=cntA_skeleton; cntB:=cntB_skeleton; fi %---------------------------------------------------------------------------------------- if f_beginchar=0: - if sw_clip=1: - f_wd#:=font_wd#*((len_x+2margin_left_right)/font_wd); - f_ht#:=font_ht#*((len_y+2margin_top_bottom)/font_ht); - font_wd:=len_x+2margin_left_right; font_ht:=len_y+2margin_top_bottom; - else: - f_wd#:=font_wd#; f_ht#:=font_ht#; - fi - beginchar(char_num,f_wd#,f_ht#,0); - f_beginchar:=1; - fi + if sw_clip=1: font_wd#:=font_wd#*((len_x+2margin_left_right)/font_wd); + font_ht#:=font_ht#*((len_y+2margin_top_bottom)/font_ht); fi + beginchar(char_num,font_wd#,font_ht#,0); f_beginchar:=1; fi for i=1 upto cntB: if lineB[i]=si_: draw_bond(i,sB[i],eB[i],angB[i],lineB[i]); fi endfor for i=1 upto cntA: @@ -418,14 +410,12 @@ def MCd(expr RW,RH)(expr FW,FH)(text s)= elseif sw_numberA=3: if numberA_end=1: - else: draw_atom(i,posA[i],br_ang[i],com_str[strA[i]],strW[strA[i]]); - fi + else: draw_atom(i,posA[i],br_ang[i],com_str[strA[i]],strW[strA[i]]); fi endfor - sft_X:=margin_left_right-min_x+(font_wd-len_x-2margin_left_right)*FW; - sft_Y:=margin_top_bottom-min_y+(font_ht-len_y-2margin_top_bottom)*FH; + sft_X:=margin_left_right-min_x+(w-len_x-2margin_left_right)*FW; + sft_Y:=margin_top_bottom-min_y+(h-len_y-2margin_top_bottom)*FH; if sw_mol_frame=1: AUX(sft_X,sft_Y)(draw_frame(len_x,len_y,(min_x,min_y),0.2pt);) fi if sw_start_vector=1: AUX(sft_X,sft_Y)(start_vector) fi addto chem_structure also currentpicture shifted (sft_X,sft_Y); @@ -631,29 +621,29 @@ if (nC>0)and(LN<>0): pickup pencircle scaled bond_pen_wd; if known colorB[n]: nB:=colorB[n]; fi if (LN=si)or(sw_bond_single=1): draw pA Cp(nB); - elseif LN=dl:draw pA Cp(nB); draw sfB(pC,gap,ap) Cp(nB); - elseif LN=dr:draw pA Cp(nB); draw sfB(pC,gap,am) Cp(nB); - elseif LN=dm:draw sfB(pB,gap/1.75,ap) Cp(nB); draw sfB(pB,gap/1.75,am) Cp(nB); - elseif LN=tm:draw pA Cp(nB);draw sfB(pA,gap,ap) Cp(nB); draw sfB(pA,gap,am) Cp(nB); + elseif LN=dl:draw pA Cp(nB); draw sfB(pC,bondgap,ap) Cp(nB); + elseif LN=dr:draw pA Cp(nB); draw sfB(pC,bondgap,am) Cp(nB); + elseif LN=dm:draw sfB(pB,bondgap/1.75,ap) Cp(nB); draw sfB(pB,bondgap/1.75,am) Cp(nB); + elseif LN=tm:draw pA Cp(nB);draw sfB(pA,bondgap,ap) Cp(nB); draw sfB(pA,bondgap,am) Cp(nB); elseif LN=wf:fill Ls--sfB(Le,ww,am)--sfB(Le,ww,ap)--cycle; elseif LN=wb:fill sfB(Ls,ww,am)--Le--sfB(Ls,ww,ap)--cycle; - elseif LN=bd:draw pA withpen penrazor rotated ap scaled gap Cp(nB); + elseif LN=bd:draw pA withpen penrazor rotated ap scaled bondgap Cp(nB); elseif LN=bz:bz_put(sfB(Ls,ww,ap),sfB(Le,ww,ap),sfB(Ls,ww,am),sfB(Le,ww,am),nB); elseif LN=zf:wz_put(Ls,sfB(Le,ww,ap),sfB(Le,ww,am),nB); elseif LN=zb:wz_put(Le,sfB(Ls,ww,am),sfB(Ls,ww,ap),nB); elseif LN=dt:for i=0 step .75zebra_gap/length(Le-Ls) until 1: drawdot i[Ls,Le]; endfor elseif LN=wv:draw_wv; - elseif LN=vf:draw pA Cp(nB);draw sfB(Le,gap,ANG-150)--Le--sfB(Le,gap,ANG+150) Cp(nB); - elseif LN=vb:draw pA Cp(nB);draw sfB(Ls,gap,ANG-30)--Ls--sfB(Ls,gap,ANG+30) Cp(nB); - elseif LN=si_:erase draw 0.15[Ls,Le]--0.85[Ls,Le] wpcs .75gap; draw pA Cp(nB); + elseif LN=vf:draw pA Cp(nB);draw sfB(Le,bondgap,ANG-150)--Le--sfB(Le,bondgap,ANG+150) Cp(nB); + elseif LN=vb:draw pA Cp(nB);draw sfB(Ls,bondgap,ANG-30)--Ls--sfB(Ls,bondgap,ANG+30) Cp(nB); + elseif LN=si_:erase draw 0.15[Ls,Le]--0.85[Ls,Le] wpcs .75bondgap; draw pA Cp(nB); elseif LN=wf_:erase fill sfB(0.15[Ls,Le],.5ww,ap)--sfB(0.15[Ls,Le],.5ww,am)-- sfB(0.85[Ls,Le],1.25ww,am)--sfB(0.85[Ls,Le],1.25ww,ap)--cycle; fill Ls--sfB(Le,ww,am)--sfB(Le,ww,ap)--cycle; elseif LN=wb_:erase fill sfB(0.15[Ls,Le],1.25ww,ap)--sfB(0.15[Ls,Le],1.25ww,am)-- sfB(0.85[Ls,Le],.5ww,am)--sfB(0.85[Ls,Le],.5ww,ap)--cycle; fill sfB(Ls,ww,am)--Le--sfB(Ls,ww,ap)--cycle; - elseif LN=bd_:erase draw 0.15[Ls,Le]--0.85[Ls,Le] wpcs 1.5gap; - draw pA withpen penrazor rotated ap scaled gap Cp(nB); + elseif LN=bd_:erase draw 0.15[Ls,Le]--0.85[Ls,Le] wpcs 1.5bondgap; + draw pA withpen penrazor rotated ap scaled bondgap Cp(nB); fi if (sw_numberB>=1)and(n>=numberB_start)and(n<=numberB_end): if sw_numberB=2: nB:=n-numberB_start+1; @@ -688,8 +678,8 @@ Ph:=Ph1:='(?6,(_dl,-2),(_dl,-4),(_dl,-6)); Ph2:='(?6,(_dl,-1),(_dl,-3),(_dl,-5)) !:='((_mk_bond,_arg_ang)); !0:='(<180,180); for i=1 upto 20: ![i]:='({{,(_get_len,0),! for j==2 upto i::,! endfor,}}); endfor Me:='(); Et:=!; Pr:='(!2); Bu:='(!3); -for i=4,5,6: for j=2 upto i-2: ?[i][j]:='((_fuse,i),(j,0)); endfor endfor -for i=5,6,7,8: for j=11 upto 15: ?[i][j]:='((_fuse,i),(j,0)); endfor endfor +for i=4,5,6: for j=2 upto i-2: ?[i][j]:='((_fuse,i),(j,0)); endfor endfor +for i=5,6,7,8: for j=11 upto 15: ?[i][j]:='((_fuse,i),(j,0)); endfor endfor %------------------------------------------------------------------------------------------------- H :='("H");C:='("C");N:='("N");O:='("O");F:='("F");S:='("S");P:='("P");I:='("I"); Si:='("{Si}");Al:='("{Al}");Mg:='("{Mg}");Zn:='("{Zn}");As:='("{As}");Cu:='("{Cu}"); @@ -715,37 +705,27 @@ def expand_set= save CH,NH,NO,OH,CHO,COOH,CN,SH; CH3:=C_HHH; NH:=N_H; NH2:=N_HH; NO2:=N_OO; OH:=O_H; CHO:=CO_H; COOH:=CO_OH; CN:=C_N; SH:=S_H; enddef; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -def font_size_set(expr m)(expr n)(expr o)(expr s)= - for j=0 upto length(s)-1: num_a:=ASCII(pic_c(j,s)); - if f_FON[num_a]=1: atom_w[num_a]:=m*atom_wd; atom_h[num_a]:=n*atom_wd; atom_d[num_a]:=o*atom_wd; fi - endfor -enddef; -def font_size_setup= font_size_set( 1)( 1)(0)("CGHMNOQ"); - font_size_set( .9)( 1)(0)("ABDEFIJKLPRSTUVWXYZ-+/>