diff options
author | Karl Berry <karl@freefriends.org> | 2018-06-18 21:01:37 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2018-06-18 21:01:37 +0000 |
commit | 1011cbf2d4d612c1af27e0b40507dac7cb40308c (patch) | |
tree | 63da68783d84f7fc66dfd783083de7b2ff98d230 /Master/texmf-dist/metapost | |
parent | 683c92e5313906003d77d51a5d3b41a16c7ce438 (diff) |
mcf2graph (18jun18)
git-svn-id: svn://tug.org/texlive/trunk@48046 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/metapost')
-rw-r--r-- | Master/texmf-dist/metapost/mcf2graph/mcf2graph.mf | 150 |
1 files changed, 103 insertions, 47 deletions
diff --git a/Master/texmf-dist/metapost/mcf2graph/mcf2graph.mf b/Master/texmf-dist/metapost/mcf2graph/mcf2graph.mf index f553da1e7dc..e2f44387b1d 100644 --- a/Master/texmf-dist/metapost/mcf2graph/mcf2graph.mf +++ b/Master/texmf-dist/metapost/mcf2graph/mcf2graph.mf @@ -1,5 +1,5 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% mcf2graph ver 4.32 Copyright (c) 2013-2018 Akira Yamaji +% mcf2graph ver 4.33 Copyright (c) 2013-2018 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, @@ -34,9 +34,9 @@ tracingstats:=1; message " This is mcf2graph ver 4.3 2018.06"; %------------------------------------------------------------------------------------------------- -newinternal nA,nB,nC,nD,nE,nF,char_num,str_cnt,sub_usr,sub_int,tbl_cnt; +newinternal nA,nB,nC,nD,nE,nF,char_num,str_cnt,sub_usr,sub_int,tbl_cnt,sharp_char; numeric save_para[],comD[][],parD[][],cntD[],tbl_str_wd[],tbl_atom[],tbl_subst[][],tbl_atom_wt[], - tbl_atom_mi[],tbl_char_wd[],tbl_char_ht[],chgA[]; + tbl_atom_mi[],tbl_char_wd[],tbl_char_ht[],andA[],and_rot[],chargeA[]; string tbl_atom_str[],strD[],var[],tag[],mp_log_name,aux_delimiter,atomfont, save_atomfont,save_defaultfont; picture mol_stru[]; @@ -119,7 +119,7 @@ def_com(-4000)(_term,_jp_atom,_jp_atom_abs,_jp_bond,_cyc,_cyc_sB,_cyc_eB,_set_li _dl,_mb,_N,_O,_S,_tmp_line,_chg_len,_get_len,_ring_len,_tmp_len,_rot_ang,_adj_ang,_chg_env, _tmp_env,_set_colorA,_set_colorB,_postA,_postB,_postC,_postD,_postE,_postF,_postG,_postH, _set_clr,_set_adr,_mk_bond,_set_atom,_arg_ang,_chg_atom,_tmp_rot,_fuse,_push,_pop, - _size_a,_numeric,_jump_at,_connect_at); + _size_a,_numeric,_jump_at,_connect_at,_set_and,_chg_charge); def_com(1)(si,dl,dr,db,dm,tm,wf,wb,bd,bz,zf,zb,dt,wv,nl,vf,vb,si_,wf_,wb_,bd_); %-------------------------------------------------------------------------------------------------- def parameter_list= @@ -199,13 +199,14 @@ def endfont= enddef; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% def set_def_MC= - save /,//,/*,*/,**,*/*,~,~~,^,^^,`,'`,<,>,>>,:>,&,:,=,\,\\,*\,\*,*\*,@,$,{,}, + save /,//,/*,*/,**,*/*,~,~~,^,^^,`,'`,<,>,>>,:>,&,:,=,\,\\,*\,\*,*\*,@,$,{,},#, |,||,|<,>|,|<=,|:,:|,_,d,w,z,inside_def_MC; inside_def_MC:=1; _:=Me; d:=db; w:=wf; z:=zf; tertiarydef a=b == change_bond(a,b) enddef; tertiarydef a:b == change_atom(a,b) enddef; def { == '''( enddef; let } == ); + def &primary s == (_set_and,ASCII(s)) enddef; vardef $primary a == a-4095 enddef; def ^^primary n == (_tmp_rot,n) enddef; def ~~primary n == (_tmp_line,n) enddef; def '`primary n == (_tmp_len,n) enddef; def :>primary n == (_tmp_env,n) enddef; @@ -213,8 +214,7 @@ def set_def_MC= def <primary n == (_rot_ang,n) enddef; tertiarydef a^b == ^^b,a enddef; tertiarydef a`b == '`b,a enddef; tertiarydef a~b == ~~b,a enddef; tertiarydef a>b == :>b,a enddef; - def & == _connect_at enddef; - def @ == _jump_at enddef; def \ == @,0 enddef; + def # == _connect_at enddef; def @ == _jump_at enddef; def \ == @,0 enddef; def \\ == \~dm enddef; def *\ == \~wf enddef; def \* == \~zf enddef; def *\* == \~wv enddef; def |: == (_push,0) enddef; def :| == (_pop,0) enddef; def |< == (_push,1) enddef; def >| == (_pop,1) enddef; @@ -319,12 +319,17 @@ vardef change_atom(expr a,b)= if (b>=H)and(b<=U):: if b==N:: PP(a,_N) elseif b==O:: PP(a,_O) elseif b==S:: PP(a,_S) else:: PX(a)(_chg_atom,b) fi - elseif b==NH:: PA(_set_clr,1) PP(a,_N) PX(a)(_postH,H) PA(_set_clr,0) - elseif b==_jump_at:: PA(_jp_atom,a) - elseif b==_connect_at:: PA(_cyc,a) + ef b==NH:: PA(_set_clr,1) PP(a,_N) PX(a)(_postH,H) PA(_set_clr,0) + ef b==_jump_at:: PA(_jp_atom,a) + ef b==_connect_at:: PA(_cyc,a) fi - elseif pair b:: PA(_set_clr,1) PX(a)(xpart(b),ypart(b)) PA(_set_clr,0) - elseif color b:: color_list[incr cntC]:=b; PX(a)(_set_colorA,cntC) + ef pair b:: + if xpart(b)==_set_and:: + PA(_set_and,ypart(b)) PA(_chg_charge,a) + else:: + PA(_set_clr,1) PX(a)(xpart(b),ypart(b)) PA(_set_clr,0) + fi + ef color b:: color_list[incr cntC]:=b; PX(a)(_set_colorA,cntC) fi fi sub_int %------- Retern value ------- enddef; @@ -465,7 +470,7 @@ def draw_dblarrow text t = draw arrow_path t enddef; %------------------------------------------------------------------------------------------------- -arrow_head:=(ahlength,-(sind 0.5ahangle)*ahlength)--(0,0)-- +arrow_head:=(0,0)--(ahlength,-(sind 0.5ahangle)*ahlength)-- (ahlength, (sind 0.5ahangle)*ahlength)--cycle; %------------------------------------------------------------------------------------------------- def ahead_angle(expr p) = @@ -502,7 +507,7 @@ def MCd(expr RW,RH)(expr FW,FH)(text TX)= begingroup save com,par,adrA,adrB,f_bra,envT,envB,lenT,lineT,strAT,stkA,stkB,stkL,stkM,cntP,bondL,temp_len, temp_cntB,f_end,f_term,rotT,adrS,f_at,f_lineT,f_rotT,f_lenT,f_envT,angT,tempB,tempA, - glu,xpos,ypos,str_len,max_x,max_y,par_s,par_e,score_u,hat,f_char,ps_adr,ps_com,sA, + glu,xpos,ypos,str_len,max_x,max_y,par_s,par_e,score_u,hat,f_char,ps_adr,ps_com,sA,sC,sD,pA, op_com,op_par,op_cnt,crR,colorA,colorB,PA,PO,PP,PX; %----------------------------------------------------------------------------------------------- def PA= sub_add enddef; @@ -512,7 +517,8 @@ def MCd(expr RW,RH)(expr FW,FH)(text TX)= %----------------------------------------------------------------------------------------------- numeric stkB[],stkA[],stkL[],stkM[],f_char[],ps_adr[],ps_com[],colorA[],colorB[], op_com[][],op_par[][],op_cnt[]; - string sA; + string sA,sC,sD; + pair pA; %----------------------------------------------------------------------------------------------- if (sw_numberA>=1)or(sw_numberB>=1): ratio_atom_bond:=0.25; fi if (sw_expand=1)or(sw_mol_out>=1): expand_set; fi @@ -543,18 +549,8 @@ def MCd(expr RW,RH)(expr FW,FH)(text TX)= 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 cntB: if lineB[i]>=si_: draw_bond(i,sB[i],eB[i],angB[i],lineB[i]); fi endfor %----------------------------------------------------------------------------------------------- - for i=1 upto cntA: - sA:=substring(3,4) of strD[numS[i]]; - if sA="+": chgA[i]:=1; ef sA="-": chgA[i]:=-1; else: chgA[i]:=0; fi - if (sw_numberA>=1)and(i>=numberA_start)and(i<=numberA_end): - if sw_numberA=2: nA:=i-numberA_start+1; - elseif sw_numberA=3: if numberA_end<cntA: nA:=numberA_end-i+1; else: nA:=cntA-i+1; fi - else: nA:=i; fi - if i<10: draw_atom(i,posA[i],0,decimal(nA),1); - else: draw_atom(i,posA[i]+(-.2atom_wd,0),0,decimal(nA),1); fi - elseif sw_numberB>=1: - else: draw_atom(i,posA[i],ang_br[i],strD[numS[i]],tbl_str_wd[numS[i]]); fi - endfor + proc_draw_atom; + proc_draw_charge; %----------------------------------------------------------------------------------------------- sftX:=margin_left_right-minX+(font_wd-mol_wd-2margin_left_right)*FW; sftY:=margin_top_bottom-minY+(font_ht-mol_ht-2margin_top_bottom)*FH; @@ -656,10 +652,48 @@ def char_use_check= endfor fi enddef; +%----------------------------------------------------------------------------------------------- +def proc_draw_atom= + for i=1 upto cntA: + if (sw_numberA>=1)and(i>=numberA_start)and(i<=numberA_end): + if sw_numberA=2: nA:=i-numberA_start+1; + elseif sw_numberA=3: if numberA_end<cntA: nA:=numberA_end-i+1; else: nA:=cntA-i+1; fi + else: nA:=i; fi + if i<10: draw_atom(i,posA[i],0,decimal(nA),1); + else: draw_atom(i,posA[i]+(-.2atom_wd,0),0,decimal(nA),1); fi + elseif sw_numberB>=1: + else: draw_atom(i,posA[i],ang_br[i],strD[numS[i]],tbl_str_wd[numS[i]]); fi + endfor +enddef; +%------------------------------------------------------------------------------------------------- +def proc_draw_charge= + for i=1 upto cntA: + if andA[i]<>0: + sA:=char(andA[i]); + nA:=ang_br[i]+and_rot[i]; + nC:=nA mod 90; + if strD[numS[i]]="": nB:=.5atom_wd; + else: + if nC<45: nB:=.85atom_wd+sind(nC)*.5atom_wd; + else: nB:=.85atom_wd+cosd(nC)*.5atom_wd; + fi + fi + pA:=sfB(posA[i]-(.35atom_wd,.35atom_wd),nB,nA); + draw_char(sA,pA,atom_wd,bond_pen_wd*ratio_char_bond,0); + else: sA:=""; + fi + nA:=length(strD[numS[i]]); + sC:=substring(nA-3,nA-2) of strD[numS[i]]; + if (sA="+")or(sC="+"): chargeA[i]:=1; + ef (sA="-")or(sC="-"): chargeA[i]:=-1; + else: chargeA[i]:=0; + fi + endfor +enddef; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% def proc_bond_atom(expr n)= f_bra:=f_end:=f_term:=rotT:=adrS:=f_lineT:=f_rotT:=f_lenT:=f_envT:=envT:=envB:=strAT:=f_at:=0; - stkL[0]:=bondL:=crR; lenT:=crR; sB[0]:=0; eB[0]:=1; lineT:=si; + stkL[0]:=bondL:=crR; lenT:=crR; sB[0]:=0; eB[0]:=1; lineT:=si; andAT:=0; for i=0 upto 5: stkA[i]:=stkB[i]:=0; endfor %----------------------------------------------------------------------------------------------- for i=n upto cntD[0]: @@ -700,7 +734,7 @@ def proc_bond_atom(expr n)= ef nC=_dl: lineB[getB(par)]:=dl; ef nC=_mb: lineB[getB(-1)]:=par; ef (nC=_chg_line)or(nC=_tmp_line): lineT:=par; - ef nC=_tmp_rot: rotT:=par; + ef nC=_tmp_rot: rotT:=par; ef nC=_cyc: f_end:=getA(par); check_adrA(f_end); add_atom; ef nC=_cyc_eB: f_end:=eB[getB(par)]; add_atom; ef nC=_cyc_sB: f_end:=sB[getB(par)]; add_atom; @@ -715,6 +749,9 @@ def proc_bond_atom(expr n)= ef nC=_term: termA; ef nC=_set_colorA: colorA[getA(adrT)]:=par; ef nC=_set_colorB: colorB[getB(adrT)]:=par; + ef nC=_set_and: andAT:=par; + ef nC=_chg_charge: andA[getA(par)]:=andAT; andAT:=0; + if rotT<>0: and_rot[getA(par)]:=rotT; fi fi endfor enddef; @@ -723,8 +760,10 @@ def add_atom= lineB[incr cntB]:=lineT; lineT:=si; if lenT=crR: lenB[cntB]:=bondL; else: lenB[cntB]:=lenT; lenT:=crR; fi - if f_bra=0: cntA:=cntA+1; sB[cntB]:=cntA; numS[cntA]:=strAT; strAT:=0; - if f_MP=1: colorA[cntA]:=colorB[cntA]:=0; fi else: f_bra:=0; fi + if f_bra=0: cntA:=cntA+1; sB[cntB]:=cntA; numS[cntA]:=strAT; + andA[cntA]:=andAT; andAT:=strAT:=and_rot[cntA]:=0; + if rotT<>0: and_rot[cntA]:=rotT; rotT:=0; fi + if f_MP=1: colorA[cntA]:=colorB[cntA]:=0; fi else: f_bra:=0; fi if f_end=0: eB[cntB]:=cntA+1; f_term:=0; else: eB[cntB]:=f_end; f_end:=0; f_term:=1; fi enddef; %------------------------------------------------------------------------------------------------- @@ -802,15 +841,30 @@ vardef getB(expr n)= if n>=1: stkB[adrS+1]+n ef n=0: tempB ef n>=-999: cntB+n+1 else: stkB[adrS]+n+4095 fi enddef; %-------------------------------------------------------------------------------------------------- -def termA= if f_term=0: if f_bra=0: numS[incr cntA]:=strAT; strAT:=0; - if f_MP=1: colorA[cntA]:=0; fi else: f_bra:=0; fi f_term:=1; fi enddef; -def termB= if f_term=0: if f_bra=0:ang_br[incr cntA]:=angT; else:f_bra:=0; fi f_term:=1; fi enddef; +def termA= + if f_term=0: + if f_bra=0: + cntA:=cntA+1; numS[cntA]:=strAT; andAT:=strAT:=and_rot[cntA]:=andA[cntA]:=0; + if rotT<>0: and_rot[cntA]:=rotT; rotT:=0; fi + if f_MP=1: colorA[cntA]:=0; fi + else: f_bra:=0; + fi + f_term:=1; + fi +enddef; +%-------------------------------------------------------------------------------------------------- +def termB= + if f_term=0: + if f_bra=0: cntA:=cntA+1; ang_br[cntA]:=angT; else:f_bra:=0; fi + f_term:=1; + fi +enddef; %-------------------------------------------------------------------------------------------------- def proc_cyc(expr n)= add_bond(angle(posA[n]-posBs)-angT); enddef; %-------------------------------------------------------------------------------------------------- -def glu_c(expr n)= if numS[n]<>0: nB:=angT mod 180; nC:=.5tbl_str_wd[numS[n]]*atom_wd; - if (nB<45)or(nB>135):glu:=glu+((sind(nB)*nC)++nC); - else :glu:=glu+((cosd(nB)*.5atom_wd)++.5atom_wd) fi fi enddef; +def glu_c(expr n)= if numS[n]<>0: nB:=angT mod 90; nC:=.5tbl_str_wd[numS[n]]*atom_wd; + if nB<45: glu:=glu+((sind(nB)*nC)++nC); + else: glu:=glu+((cosd(nB)*.5atom_wd)++.5atom_wd) fi fi enddef; %-------------------------------------------------------------------------------------------------- vardef proc_env(expr n,m,a,b)= r:=(n mod 360); if m>=sub_emb_start: parD[m][cntB-temp_cntB] else: @@ -962,14 +1016,14 @@ Me:='(); Et:='(!); Pr:=!x2:='(!,!); Bu:=!x3:='(!,!,!); 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");S:='("S");P:='("P"); -H[1]:='("{H^+^}");H[-1]:='("{H^-^}");C[1]:='("{C^+^}");C[-1]:='("{C^-^}"); -O[1]:='("{O^+^}");O[-1]:='("{O^-^}");N[1]:='("{N^+^}");N[-1]:='("{N^-^}"); -S[1]:='("{S^+^}");S[-1]:='("{S^-^}");P[1]:='("{P^+^}");P[-1]:='("{P^-^}"); -F:='("F");I:='("I"); +H :='("H");C:='("C");N:='("N");O:='("O");S:='("S");P:='("P");F:='("F");I:='("I"); Si:='("{Si}");Al:='("{Al}");Mg:='("{Mg}");Zn:='("{Zn}");As:='("{As}");Cu:='("{Cu}"); Ag:='("{Ag}");Au:='("{Au}");Sn:='("{Sn}");Cl:='("{Cl}");Br:='("{Br}");Li:='("{Li}"); Na:='("{Na}");Ca:='("{Ca}");Hg:='("{Hg}");Ni:='("{Ni}");Ti:='("{Ti}");U:='("U"); +H[1]:='("{H^+^}");H[-1]:='("{H^-^}");C[1]:='("{C^+^}");C[-1]:='("{C^-^}"); +O[1]:='("{O^+^}");O[-1]:='("{O^-^}");N[1]:='("{N^+^}");N[-1]:='("{N^-^}"); +S[1]:='("{S^+^}");S[-1]:='("{S^-^}");P[1]:='("{P^+^}");P[-1]:='("{P^-^}"); +Li[1]:='("{Li^+^}"); Na[1]:='("{Na^+^}"); Cl[-1]:='("{Cl^-^}"); Br[-1]:='("{Br^-^}"); %------------------------------------------------------------------------------------------------- R:='("R"); R1:='("{R^1^}"); R2:='("{R^2^}"); R3:='("{R^3^}"); R4:='("R^4^"); R5:='("{R^5^}"); %------------------------------------------------------------------------------------------------- @@ -1017,7 +1071,7 @@ char_size_set(.35)(.9)("i"); char_size_set(.4)( 1)(".,:;'`^"); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% def draw_char(expr CHR,POS,WD,PEN,NUM)= -save Z,aW,aH,fW,fH,hW,hW,hH,fP,hP,pathO,pathOh,pos,dw,dwh,dwv,cdw,ppcs,sbp; +save Z,aW,aH,fW,fH,hW,hW,hH,fP,hP,pathO,pathOh,pos,dw,dwh,dwv,cdw,ppcs,sbp,sC; path pathO,pathOh; string sC; pair Z[],pos; @@ -1127,7 +1181,7 @@ ef sC="_": dwh Z03--Z21; ef sC="=": dwh (hP,.3aH)--(fW,.3aH); dwh (hP,.6aH)--(fW,.6aH); ef sC="/": dw (fW,fH)..Z01; ef sC="+": dwv Z19--Z14; dwh Z09--Z10; -ef sC="*": dw Z19--Z14; dw Z09--Z10; dw (fW,fH)--Z01; dw Z13--Z21; +ef sC="*": dw Z19--Z14; dw Z09--Z10; dw (.2aW,.2aH)--(.8aW,.8aH); dw (.2aW,.8aH)--(.8aW,.2aH); else: fi enddef; @@ -1138,12 +1192,14 @@ vardef fixed_l(expr n)(expr s)= s&(substring(0,n-length(s)) of blank_str) enddef vardef fdr(expr n)(expr s)=fixed_r(n)(decimal(s)) enddef; vardef fdl(expr n)(expr s)=fixed_l(n)(decimal(s)) enddef; def warning(expr s)= message "% "&decimal(char_num)&fdr(3)(incr warning_cnt)&")"&s; enddef; +%-------------------------------------------------------------------------------------------------- def bond_check(expr a)(text s)= nF:=0; for list=s: if list=bond_cnt: nF:=1; fi endfor if nF=0: warning("A"&decimal(a)&" ( "&fixed_l(8)(strD[numS[a]])&") has"&fdr(2)(bond_cnt)&" bonds"); fi enddef; +%-------------------------------------------------------------------------------------------------- vardef stripP(expr a)= if length(a)=4: substring (1,3) of a elseif length(a)=6: substring (1,2) of a @@ -1298,7 +1354,7 @@ def proc_report_out= fdr(10)(round_auto(ypart(posA[i])/bond_len))&" ) "&fixed_l(8)(strD[numS[i]])& " "&fdr(3)(Bcnt[i]) if hideH[i]>0: &fdr(8)(hideH[i]) else: &" " fi - if chgA[i]<>0: &fdr(8)(chgA[i]) fi; + if chargeA[i]<>0: &fdr(8)(chargeA[i]) fi; endfor message "------------------------------------------------------------------"; message "< NO. >< bond (sdt)><angle + ( +- )><length ( pt )>"; @@ -1350,7 +1406,7 @@ def proc_mol_out= for i=1 upto cntA: printf fdr(10)(xpart(posA[i])/bond_len)& fdr(10)(ypart(posA[i])/bond_len)& fdr(10)(0)&" "&fixed_l(2)(stripP(strD[numS[i]]))&" 0 0 0 0"; - if chgA[i]<>0: chg_atm[incr chg_cnt]:=i; chg_chg[chg_cnt]:=chgA[i]; fi + if chargeA[i]<>0: chg_atm[incr chg_cnt]:=i; chg_chg[chg_cnt]:=chargeA[i]; fi endfor for i=1 upto cntB: if lineB[i]<>0: if (lineB[i]=dl)or(lineB[i]=dr)or(lineB[i]=dm): nA:=2; @@ -1377,7 +1433,7 @@ def proc_mol_out= for i=1 upto cntA: printf "M V30 "&decimal(i)&" "&stripP(strD[numS[i]])&" "& decimal(xpart(posA[i])/bond_len)&" "&decimal(ypart(posA[i])/bond_len)&" 0 0" - if chgA[i]<>0: &" CHG="&decimal(chgA[i]) fi; + if chargeA[i]<>0: &" CHG="&decimal(chargeA[i]) fi; endfor printf "M V30 END ATOM"; printf "M V30 BEGIN BOND"; |