after seeing this answer, I tried to make my own ball and stick model of a diagram. So I made the following code:
\documentclass{standalone}
\usepackage[inline]{asymptote}
\begin{document}
\begin{asy}
size(300);
import solids;
// 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[] Hydrgeon={
C1,C2,C3,C4,C5,C6,C7,C8,C9,C10,
}
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;
}
)
);
}
real cylR=0.062;
pen connectPen=lightgray
Draw(C1--N1,connectPen)
Draw(N1--C2,connectPen)
Draw(C2--C3,connectPen)
Draw(C3--C4,connectPen)
Draw(C4--O1,connectPen)
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)
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;}
)
);
}
}
drawSpheres(Carbon,darkgray);
drawSpheres(Nitrogen,lightblue);
drawSpheres(Oxygen,red);
drawSpheres(Hydrogen,lightgray);
\end{asy}
\end{document}
Unfortunately it returns the error could not load module [filedirectory-1.asy]. I saw this link here and tried to resolve the issue by making a config.asy file, and so it looks like this:
import settings;
dir="C:\Program Files\Asymptote";
But unfortunately it still does not render and gives the same error. Is there any way to resolve this issue (other asymptote diagrams work perfectly including the one where I was inspired from)?
Also, though this should probably be put as a separate question, how do I draw a double bond using the cylinder connectors in the code above?


Hydrgeon, which should beHydrogenand many;. – Oct 17 '18 at 13:57