Official Asymptote example – cyclohexane

Category: Asymptote,Official Gallery One-PagerPh. Ivaldi @ 6 h 57 min

Figure 0042
(Compiled with Asymptote version 2.14svn-r5318)
/* This code comes from The Official Asymptote Gallery */
    
import three;

currentprojection=perspective(300,-650,500);
currentlight.background=palecyan;

surface carbon=scale3(70)*unitsphere; // 70 pm
surface hydrogen=scale3(25)*unitsphere; // 25 pm

real alpha=90+aSin(1/3);

real CCbond=156; // 156 pm
real CHbond=110; // 110 pm

triple c1=(0,0,0);
triple h1=c1+CHbond*Z;
triple c2=rotate(alpha,c1,c1+Y)*(CCbond*Z);
triple h2=rotate(120,c1,c2)*h1;
triple h3=c2-CHbond*Z;
triple h4=rotate(120,c2,c1)*h3;

triple c3=rotate(120,c2,h3)*c1;
triple h5=c3+CHbond*Z;
triple h6=rotate(-120,c3,c2)*h5;

triple c4=rotate(-120,c3,h5)*c2;
triple h7=c4-CHbond*Z;
triple h8=rotate(120,c4,c3)*h7;

triple c5=rotate(120,c4,h7)*c3;
triple h9=c5+CHbond*Z;
triple h10=rotate(-120,c5,c4)*h9;

triple c6=rotate(-120,c5,h9)*c4;
triple h11=c6-CHbond*Z;
triple h12=rotate(120,c6,c5)*h11;

pen Black=gray(0.4);

defaultrender=render(compression=Zero,merge=true);

draw(shift(c1)*carbon,Black);
draw(shift(c2)*carbon,Black);
draw(shift(c3)*carbon,Black);
draw(shift(c4)*carbon,Black);
draw(shift(c5)*carbon,Black);
draw(shift(c6)*carbon,Black);


material White=material(diffusepen=gray(0.4),emissivepen=gray(0.6));

draw(shift(h1)*hydrogen,White);
draw(shift(h2)*hydrogen,White);
draw(shift(h3)*hydrogen,White);
draw(shift(h4)*hydrogen,White);
draw(shift(h5)*hydrogen,White);
draw(shift(h6)*hydrogen,White);
draw(shift(h7)*hydrogen,White);
draw(shift(h8)*hydrogen,White);
draw(shift(h9)*hydrogen,White);
draw(shift(h10)*hydrogen,White);
draw(shift(h11)*hydrogen,White);
draw(shift(h12)*hydrogen,White);


pen thick=linewidth(10);

draw(c1--c2--c3--c4--c5--c6--cycle,thick);

draw(c1--h1,thick);
draw(c1--h2,thick);
draw(c2--h3,thick);
draw(c2--h4,thick);
draw(c3--h5,thick);
draw(c3--h6,thick);
draw(c4--h7,thick);
draw(c4--h8,thick);
draw(c5--h9,thick);
draw(c5--h10,thick);
draw(c6--h11,thick);
draw(c6--h12,thick);

Étiquettes : , ,


Official Asymptote example – eetomumu

Category: Asymptote,Official Gallery One-PagerPh. Ivaldi @ 15 h 57 min

Figure 0051
(Compiled with Asymptote version 2.14svn-r5318)
/* This code comes from The Official Asymptote Gallery */
    
import feynman;


// set default line width to 0.8bp
currentpen = linewidth(0.8);

// scale all other defaults of the feynman module appropriately
fmdefaults();

// define vertex and external points

real L = 50;

pair zl = (-0.75*L,0);
pair zr = (+0.75*L,0);

pair xu = zl + L*dir(+120);
pair xl = zl + L*dir(-120);

pair yu = zr + L*dir(+60);
pair yl = zr + L*dir(-60);


// draw propagators and vertices

drawFermion(xu--zl);
drawFermion(zl--xl);

drawPhoton(zl--zr);

drawFermion(yu--zr);
drawFermion(zr--yl);

drawVertex(zl);
drawVertex(zr);


// draw momentum arrows and momentum labels

drawMomArrow(xl--zl, Relative(left));
label(Label("$k'$",2RightSide), xl--zl);

label(Label("$k$",2LeftSide), xu--zl);

drawMomArrow(zl--zr, Relative(left));
label(Label("$q$",2RightSide), zl--zr);

drawMomArrow(zr--yu, Relative(right));
label(Label("$p'$",2LeftSide), zr--yu);

label(Label("$p$",2RightSide), zr--yl);


// draw particle labels

label("$e^-$", xu, left);
label("$e^+$", xl, left);

label("$\mu^+$", yu, right);
label("$\mu^-$", yl, right);

Étiquettes : , ,


Official Asymptote example – fermi

Category: Asymptote,Official Gallery One-PagerPh. Ivaldi @ 2 h 57 min

Figure 0063
(Compiled with Asymptote version 2.14svn-r5318)
/* This code comes from The Official Asymptote Gallery */
    
import feynman;

// set default line width to 0.8bp
currentpen = linewidth(0.8);

// scale all other defaults of the feynman module appropriately
fmdefaults();

// disable middle arrows
currentarrow = None;

// define vertex and external points

pair xu = (-40,+45);
pair xl = (-40,-45);
pair yu = (+40,+45);
pair yl = (+40,-45);

pair zu = (  0,+ 5);
pair zl = (  0,- 5);

// define mid points

pair mxu = (xu+zu)/2;
pair mxl = (xl+zl)/2;
pair myu = (yu+zu)/2;
pair myl = (yl+zl)/2;

// draw fermion lines
drawFermion(xu--zu--yu);
drawFermion(xl--zl--yl);

// draw vertices
drawVertexOX(zu);
drawVertexOX(zl);

// draw gluon. Note that the underlying fermion line is blotted out.
drawGluon(arc((0,0),mxu,myl,CW));

// shipout

Étiquettes : ,


Official Asymptote example – pdb

Category: Asymptote,Official Gallery One-PagerPh. Ivaldi @ 14 h 57 min

Figure 0152
(Compiled with Asymptote version 1.87svn-r4652)
/* This code comes from The Official Asymptote Gallery */
    
import three;
import cpkcolors;

// A sample Protein Data Bank file for this example is available from
// http://ndbserver.rutgers.edu/ftp/NDB/coordinates/na-biol/100d.pdb1

bool getviews=true;

currentlight=White;
//currentlight=nolight;

size(200);
currentprojection=perspective(30,30,15);

// Uncomment this line for more accurate (but slower) PDF rendering
//dotgranularity=0;

pen chainpen=green;
pen hetpen=purple;

string filename="100d.pdb1";
//string filename=getstring("filename");

string prefix=stripextension(filename);
file data=input(filename);

pen color(string e) 
{
  e=replace(e," ","");
  int n=length(e);
  if(n < 1) return currentpen;
  if(n > 1) e=substr(e,0,1)+downcase(substr(e,1,n-1));
  int index=find(Element == e);
  if(index < 0) return currentpen;
  return rgb(Hexcolor[index]);
}       

// ATOM
string[] name,altLoc,resName,chainID,iCode,element,charge;
int[] serial,resSeq;
real[][] occupancy,tempFactor;

bool newchain=true;

struct bond 
{
  int i,j;
  void operator init(int i, int j) {
    this.i=i;
    this.j=j;
  }
}

bond[] bonds;

struct atom 
{
  string name;
  triple v;
  void operator init(string name, triple v) {
    this.name=name;
    this.v=v;
  }
}

struct chain
{
  int[] serial;
  atom[] a;
}

int[] serials;
chain[] chains;
atom[] atoms;

while(true) {
  string line=data;
  if(eof(data)) break;
  string record=replace(substr(line,0,6)," ","");
  if(record == "TER") {newchain=true; continue;}
  bool ATOM=record == "ATOM";
  bool HETATOM=record == "HETATM";
  int serial;

  atom a;
  if(ATOM || HETATOM) {
    serial=(int) substr(line,6,5);
    a.name=substr(line,76,2);
    a.v=((real) substr(line,30,8),
         (real) substr(line,38,8),
         (real) substr(line,46,8));
  }
  if(ATOM) {
    if(newchain) {
      chains.push(new chain);
      newchain=false;
    }
    chain c=chains[chains.length-1];
    c.serial.push(serial);
    c.a.push(a);
    continue;
  }
  if(HETATOM) {
    serials.push(serial);
    atoms.push(a);
  }
  if(record == "CONECT") {
    int k=0;
    int i=(int) substr(line,6,5);
    while(true) {
      string s=replace(substr(line,11+k,5)," ","");
     if(s == "") break;
      k += 5;
      int j=(int) s;
      if(j <= i) continue;
      bonds.push(bond(i,j));
     }
  }
}

write("Number of atomic chains: ",chains.length);

int natoms;
for(chain c : chains) {
  for(int i=0; i < c.a.length-1; ++i)
    draw(c.a[i].v--c.a[i+1].v,chainpen,currentlight);
  for(atom a : c.a)
    dot(a.v,color(a.name),currentlight);
  natoms += c.a.length;
}

write("Number of chained atoms: ",natoms);
write("Number of hetero atoms: ",atoms.length);

for(atom h : atoms)
  dot(h.v,color(h.name),currentlight);

write("Number of hetero bonds: ",bonds.length);

for(bond b : bonds) {
  triple v(int i) {return atoms[find(serials == i)].v;}
  draw(v(b.i)--v(b.j),hetpen,currentlight);
}

string options;
string viewfilename=prefix+".views";

if(!error(input(viewfilename,check=false)))
  options="3Dviews="+viewfilename;

if(getviews) {
  picture pic;
  add(pic,embed("label",currentpicture,options=options),(0,0),N);
  label(pic,cameralink("label"),(0,0),S,fontsize(12pt));
  shipout(prefix,pic,options=options);
} else
  shipout(prefix,options=options);

Étiquettes : , , , , ,