1

After seeing this answer, i tried to draw a bond withe 2 colors using the cylinder connectors like this image:

enter image description here

So I used the given code but i get error (i used Texstudio and Texmaker).

\documentclass{standalone}
\usepackage{asypictureB}
\begin{document}
\begin{asypicture}{name=crystal}
size(300);
import solids;

currentprojection=orthographic ( camera=(8,5,4), up=(0,0,1), target=(2,2,2), zoom=0.5 );

// save predefined 2D orientation vectors pair NN=N; pair SS=S; pair EE=E; pair WW=W;

triple C1 = (-3.19898,0.68575,-0.09137); triple N1 = (-2.00788,-0.15303,-0.05472); triple H1 = (-3.17155,1.39571,-0.92422); triple H2 = (-3.31563,1.23754,0.84706); triple H3 = (-4.08519,0.05549,-0.21396); triple C2 = (-0.78815,0.67831,0.01256); triple H4 = (-1.95362,-0.69266,-0.92177); triple C3 = (0.47237,-0.18670,0.21998); triple H5 = (-0.86520,1.39211,0.84227); triple H6 = (-0.69535,1.26040,-0.91400); triple C4 = (1.73163,0.67172,0.09304); triple N2 = (0.51467,-1.32801,-0.73516); triple H7 = (0.46502,-0.59296,1.23918); triple H8 = (1.39360,-1.82407,-0.57104); triple H9 = (-0.23067,-1.96899,-0.46111); triple O1 = (1.80456,1.88884,0.13111); triple O2 = (2.86188,-0.07112,0.00360); triple H10 = (3.57354,0.59879,-0.06651);

triple[] Carbon={
C1,C2,C3,C4 }; triple[] Nitrogen={ N1,N2 }; triple[] Oxygen={ O1,O2 }; triple[] Hydrogen={ H1,H2,H3,H4,H5,H6,H7,H8,H9,H10 };

//%place non-atom cube corners

real cylR=0.15;

void Draw(guide3 g,pen p=currentpen){ draw( cylinder( point(g,0),cylR,arclength(g),point(g,1)-point(g,0) ).surface( new pen(int i, real j){ return p; } ) ); } void DrawTwoColors(guide3 g,pen p=currentpen,pen q=currentpen){ draw( cylinder( point(g,0),cylR,arclength(g)/2,point(g,1)-point(g,0) ).surface( new pen(int i, real j){ return p; } ) ); draw( cylinder( point(g,1),cylR,arclength(g)/2,point(g,0)-point(g,1) ).surface( new pen(int i, real j){ return q; } ) ); }

pen connectPen=lightgray; pen connectPenH=lightgray; pen connectPenN=lightblue; pen connectPenO=red; pen connectPenC=darkgray; //Draw(C1--N1,connectPen); DrawTwoColors(C1--N1,connectPenC,connectPenN); Draw(N1--C2,connectPen); Draw(C2--C3,connectPen); Draw(C3--C4,connectPen); //Draw(C4--O1,connectPen); DrawTwoColors(C4--O1,connectPenC,connectPenO); Draw(H1--C1,connectPen); Draw(H2--C1,connectPen); Draw(H3--C1,connectPen); Draw(H4--N1,connectPen); Draw(C2--H5,connectPen); Draw(C2--H6,connectPen); Draw(C3--H7,connectPen); Draw(C3--N2,connectPen); Draw(N2--H8,connectPen); Draw(N2--H9,connectPen); //Draw(C4--O2,connectPen); DrawTwoColors(C4--O2,connectPenC,connectPenO); Draw(O2--H10,connectPen);

void drawSpheres(triple[] C, real R, pen p=currentpen){ for(int i=0;i<C.length;++i){ draw(sphere(C[i],R).surface( new pen(int i, real j){return p;} ) ); } }

real radC=0.45; real radN=0.6; real radO=0.6; real radH=0.3;

drawSpheres(Carbon,radC,darkgray); drawSpheres(Nitrogen,radN,lightblue); drawSpheres(Oxygen,radO,red); drawSpheres(Hydrogen,radH,lightgray);

\end{asypicture} \end{document}

@quark67 I still have the same errors.

This is screenshoots of all my steps:

1- When i choose Build & View, i get:

enter image description here

2- When i choose Tools ▶︎ User ▶︎ 1:Asypicture:

enter image description here

I get this errors :

enter image description here

@quark67 yes i am on windows 10 and this is my sitting page:

enter image description here

moumou85
  • 423
  • 1
    Which error did you get? – Marijn Mar 08 '23 at 06:31
  • ! LaTeX Error: File `cell-crystal' not found.See the LaTeX manual or LaTeX Companion for explanation.Type H for immediate help.... \end{asypicture}

    ! I can't write on file `cell-compile_asy.bat'.\endgroup \set@typeset@protect \end{document}

    – moumou85 Mar 08 '23 at 12:35
  • I will write a step by step answer. In short, you need activate shell-escape. Note that TexStudio is not my main tool, so perheps there is a better method. – quark67 Mar 08 '23 at 13:19
  • See also https://tex.stackexchange.com/questions/598818/how-can-i-enable-shell-escape, for enabling shell-escape, both TexStudio and TexMaker are covered in that question. – Marijn Mar 08 '23 at 13:40
  • Can you add a screenshot of what exactly does Tools > User > Asypicture ? What contain this user command in the settings? Perhaps there is a typo in the command (also perhaps are you on Windows? Sadly, I don't know Windows). Perhaps on Windows you should add .exe or .bat? Take a look at https://tex.stackexchange.com/questions/117287/setup-asymptote-in-texmaker, at https://tex.stackexchange.com/a/99476/132405, at https://texstudio-org.github.io/configuration.html. I hope a Windows user can be more helpful than me. – quark67 Mar 09 '23 at 11:59
  • @quark67 how can i draw a bond withe 2 colors using Asymptote. – moumou85 Mar 09 '23 at 18:36
  • It's like [--shell-escape] doesn't work on Windows (see the orange warning in the message box). I don't know more (not a Windows user). Add the windows and texstudio tags (and also perhaps in the title of the question, so it can attract more attention). – quark67 Mar 09 '23 at 21:59
  • Ok @quark67 and thank you very much for your answers. – moumou85 Mar 10 '23 at 08:43

1 Answers1

1

In TeXstudio, create the file with the code and name it for example test-crystal.tex.

Go to the TeXstudio settings, and choose Buid. Then click on the + Add button:

enter image description here

You will see: enter image description here

In (1) write for example: Asypicture

In (2), write: txs:///pdflatex/[--shell-escape].

Then click on the button OK (at bottom right of the setting window in the Mac version) to validate the change.

Then choose Tools ▶︎ User ▶︎ 1:Asypicture.

enter image description here

Wait few seconds, then you will see: enter image description here

And a bunch of files in the directory of the test-crystal.tex file. In these files, the .pdf file (yes there is also a file named test-crystal-crystal_errors.txt but here it is blank): enter image description here

And it contain what you expect: enter image description here

quark67
  • 4,166
  • Thank you very much quark67 and Marijn for your efforts, I did exactly as you (quark67) told me but I get the following errors: Package asypictureB Error: File `cell-crystal' not found. \end{asypicture} – moumou85 Mar 08 '23 at 20:28
  • @moumou85 I have this message when I click directly on the Build button, but not when I go to Tools > User > Asymptote chain. Can you edit your question with screenshoots of all yours steps please? – quark67 Mar 08 '23 at 21:02