Showing posts with label scripting. Show all posts
Showing posts with label scripting. Show all posts

Tuesday, March 23, 2010

Evolution Simulation IV: Mutating critters at last!

As noted in my last post I was finding all sorts of problems with my region. Turns out that these were due to two things. First to control my critters I was killing them off bu broadcasting a commmand that triggers the llDie() function. But too many prims dying at once was messing up the asset server.

Also I was duplicating the critters en mass and that I led the server to treat my critters as the dreaded grey goo. Grey goo is a term for excessive rapid self replicating prims. See this discussion of the origin of the term from nanotechnology. When Second Life, and apparently OpenSim as well, detects too rapid prim replication this is treated as grey goo and a defense against this called the grey goo fence is activated.

Open Sim apparently doesn't warn you about this and I only discovered the problem when experimenting with my critters in Second Life. Second Life does warn you about grey goo and I got the warning rezzing even a small number of critters at once. Apparently the limit is about 240 rezzings in 6 seconds. Beyond that the ability to rez those prims is restricted. My inadvertant experiments suggest that in SL the limit may be more stringent than 240 rezzings in 6 seconds.

See http://lslwiki.net/lslwiki/wakka.php?wakka=GreyGooFence for a discussion of Grey Goo and the Grey Goo Fence.

This last week I worked out how to input and represent the critters genetics and the mutation routines. In my earlier systems I had the critters read their initial genetics from a note card. Instead I use the object description field to enter and store the genetics as a string of integers.

Right now the description field has 4 digits

position 1 = "1" or "2" "1" = haploid "2" = diploid. Right now the critters are strictly haploid so this position is ignored for now.

Position 2, 3, 4 are three loci each with 9 possible alleles represented by single character "0" through "9". For the haploid critters, this means there are 1,000 possible genotypes.

Since I mean my evolution simulation to be visual the genotypes in the three loci are used to make a vector that can be used with the llSetColor function.

So in the object description field the legitimate genetic description would be
"1045" . When a new critter is rezzed, the description can be passed to the offspring through the parameter in the llRezObject function.

I also wrote a mutation function:

string mutation(string start, float mforward, float mback)

Where the string is the genetic description, mforward and mback are forward and back mutation rates going forward to the next allele and mback the back mutation rate to the previous allele. So I assume if the allele is "7" then forward mutation would lead to a change to "8", and back would change from "7" to "6".

In addition another function setcolor(string thedata) takes the genetic string, isolated the loci and uses them to set the color of the critter and display the genetic description as using llSetText. I did this because just as in real populations most of the genetic variation leads to subtle variation in the population phenotypes over the short run.

The image shows the results. The critters started out with the color <.9, 0 .9> which sort of a light bluish green. After 4 generations of mutations if you look at the image you can see subtle differences resulting from successive mutations.

The critters still don't really interact with each other and wander around randomly, but not leaving my region. I did some work streamlining this routine so it was much more efficient.

Next up....adding simple natural selection to the mix.

Monday, February 22, 2010

NMC SL Pro Conference...

The NMC SL Pro conference begins tomorrow and I will be there in amongst my first life teaching and meetings so I think my laptop will be my special friend through Thursday. The focus is on scripting...so hope to get some good tips. The schedule is here:

http://www.nmc.org/2010-slpro/program

Saturday, February 20, 2010

The Selfish Herd: OpenSim Evolution Simulation II

Been a bit distracted by academics but this week worked a bit on my evolution simulation. First I put limits on my critters so that if they escape my parcel they die. Next I set up a controller that uses or at least attempts to use llGetParcelPrimCount in a timer event to count my organisms and kill them all if the population grows beyond a certain size.

The script is straightforward:

But the script does seem to update the prim count properly in OpenSim unless I touch the prim with the script. What's weird is that I have used a very similar script in SL and it updates fine.

The other thing I have been working on is the duplication script itself. I am using the basic script givenn in the LSL Wiki at this link.

http://lslwiki.net/lslwiki/wakka.php?wakka=ExampleSelfReplication

This gives a pretty complete list of precautions if you want to make self replicating critters. So should you decide that you need some sort of self replicating critters pay real close attention lest you get the grey goo.

Right now I have the basic replication scheme worked into my code but right now the critters replicate only on a command from me...so they are on a pretty tight leash. The picture accompanying this post is after 8 doublings from a single critter. My critter sensing prim did not pick up that there were more than 128 critters so it is good thing I am not letting these things replicate on their own! The critters remind me of a herd hence the Selfish Herd after W. D. Hamilton's famous paper: Geometry for the selfish herd. J. theor. Biol. 31:295-311.

Thursday, June 4, 2009

Particle fun

In building my protein synthesis model, I really don't want to use more prims than needed. At the same time I want to display the results in a more interesting way than than as a string. So I have been playing with a particle system.

Here's the result. The script is modified from a snippit of script that generates a particle banner by Debbie Trilling, part of her Random AV profile script.

I tweaked those settings to give two functions that collectively take a text string and converts it into a string of particles. One could use this to display text messages, but here I am using it to display the one letter amino codes of a proteins primary structure. The colors represent the type of amino acid (non polar, acidic, polar non ionizing etc). Of course you have to put a texture for each symbol.

The two functions I developed to represent the protein's primary structure as a string of particles

particleletter(string texture, float distance, float size)


particlemessage(string message, float distance, float size, float speed)

This system unfortunately does not work reliably in that the individual particles are not always produced so the display will have gaps in it. This is a big problem with long polypeptides such as this one here which is the primary structure of an opsin protein.

Another limitation is that the particles only last for a minute or so.

For the student version I will use a small polypeptide with 10-12 residues, that way the DNA template and RNA will require only 30 or so DNA bases. That is a lot more practical.

Monday, May 11, 2009

Sabbatical Presentation

Last Thursday I gave my Sabbatical report on my Second Life activities this semester. It is only about 20 minutes long so it is really difficult to say and show everything one might want to show. The video was just posted today so if you want to see my take on what to say about Second Life in less than 20 minutes have a look at:

http://video.jccc.edu/publicvid/innovations/PaulDecelles.asx

Saturday, April 18, 2009

Evolution III: the Predator version...

My natural selection module works pretty well but one concern was how to make it a bit more interesting. One obviously way to do that would be to make Cami's that move so that they are harder to spot and catch.

So since I really don't know a whole lot about making things move in Second Life, the first thing I did was develop a cami that will roam around randomly but stay in my land.

The strategy I developed builds on a function I had previously scripted for random movement of a prim:
//--------------------------------
vector newcoodinates(vector pos ,float pathlength, integer start)
{

integer icount;
float deltax;
float deltay;
vector temp;
float ground;
temp = llGetPos();
if (start = TRUE)
{
deltax = llFrand(pathlength)-pathlength/2;
deltay = llFrand(pathlength)-pathlength/2;
temp.x = temp.x + deltax;
temp.y = temp.y + deltay;
ground = llGround(<0.0,0.0,0.1>);

temp.z = ground;
if (llGetLandOwnerAt(temp) == llGetOwnerKey(llGetKey()))
{

return temp;
}
else {

return pos;
}
}

return temp;
}
//---------------------------------------------------

The idea is to take the prim's current position and update it with a "random" number between zero and some maximum path length. That's what this statement does in the one dimension:

deltax = llFrand(pathlength)-pathlength/2;

Since I want the cami's to hug the ground for the vertical dimension I use LSL's llGround function:

ground = llGround(<0.0,0.0,0.1>); the result is the vertical dimension.


One thing that flummoxed me for awhile was how to keep the cami in bounds. My original idea was to have the cami detect when it was on someone else's land and have it turn around and leave. But that turned out to be more difficult to script in a totally fool proof manner to this trigonometrically challenged scriptor. Besides, it seemed much better and nicer, to stop the cami from even entering someone's land in the first place:





So that's what this piece of code does:

if (llGetLandOwnerAt(temp) == llGetOwnerKey(llGetKey()))
{

return temp;
}
else {

return pos;
}

The rest of the basic movement script is deceptively simple:

default
{

state_entry()
{

do {

newpos = newcoodinates(llGetPos() ,2,start);
llSetRot(llEuler2Rot(<0,0,-pi/2>)*llGetRot());
llLookAt(newpos,1,0);
llSetPos(newpos);


llStopLookAt();


}
while (start==TRUE);

}
}

The rotation functions are sort of trial and error on my part but the cami's end up with an interesting waddling motion, so I am pleased with that even if it wasn't quite what I wanted at first.

Deceptively simple because I also needed toggle that stops the cami's so I can catch them and for determining the cami genotypes and phenotypes. Fortunately my previous cami scripts are easily modified to to work with my cami movement script.

The result is Natural Selection the Predator version right now at:

http://slurl.com/secondlife/Carmine/123/151/135

Just touch the light blue prim and 50 maddingly difficult to catch cami's will start swarming around:















The idea is to put yourself
in the role of a predator selecting against one of the phenotypes. The phenotypes use my cami genetics scripts and it is possible to select against one of the phenotypes and eliminate the genes for that phenotype, but its harder than it looks.

This version will allow you to keep selecting until the the cami's derez at which point you must touch the blue prim again to rez the next generation of cami's using the ones you didn't get as the parent population. I may change this feature.

The main script in the cube again handles all the book keeping and generates a report tracking the allele frquencies when you touch it to rez the next generation.

By the way, when you touch one of the camis in your role as predators they explode red blood thanks to a little particle script...next will be sound effects.

So even if you don't know squat about population genetics or evolution, at least you get to blow up stuff. I guess there is a bit of adolescent even in the most prim and proper of us.

Oh if you visit, watch out for cami sharks.




















This week I will be designing some suggested activities related to evolution using my cami system and also taking a few days for a trip to the Ozarks for springtime dogwood viewing, I hope.

Tuesday, April 14, 2009

Evolution II 101 Dalmations?

Well no, how about 30 Caminalcules after selection favoring a recessive allele for 8 generations. The natural selection module beta is finished and works very well. The basic strategy is to have the user or users act as visual predators removing camis from the population. The module might for instance be on a certain background where some cami phenotypes are real obvious while others are not.

The "predators" remove cami's by touching them, and the population is up dated. After a set period of time say 1 minute the remaining cami's are used to make a new population, which the module generates when it is touched and the cycle is repeated until only one genotype remains or until the users give up.

At the start of each generation the module generates a report in chat on the screen showing the allele frequencies for both of the cami loci.

If Cami's are never "eaten" the result is genetic drift. So this module really combines genetic drift and natural selection. It does not use or even compute selection coefficients, but one could add that to a report.

Monday, April 13, 2009

A Scripting Interlude

While revisiting my genetic drift module and starting my natural selection module, I decided to fix a potentially annoying problem. Since Caminalcules rez as physical objects sometimes they behave really flaky and end up in other regions. Right now they are set to die on their own after a set time but that would be a scant comfort to another land owner who has one of these things appear on her land.

With the help of the good folks in the College of Scripting Music Science group here's the basic strategy...

default {
state_entry()
{
llSetTimerEvent(1.0);
}
timer()
{
// check if the touching person is over the script owner's land

if (llOverMyLand(llGetKey())) {
llSay(0, "the prim is on my land.");
} else {
llSay(0, "the prim is NOT on my land.");
llDie();
}
}
}

Not real hard and experienced scripters probably know about llOverMyLand, but it solves one of life's little mysteries. I can of course shorten this to a single if statement if I just want the critter to die, but I might want different sorts of behavior depending where the critter is, hmmmmm.

By the way, since I have several parcels, I was interested to find that llOverMyLand doesn't care what parcel the object is in just whether or not you own the parcel.

Saturday, April 11, 2009

A certain cell membrane...

My biology viewers might recognise what this SL model is supposed to be.

Membrane of a certain cell

This is a preliminary prototype for a neuron membrane showing stylised transport proteins (purple). The round guys with the lids are gated sodium proteins the lidless tubes are gated potassium channel proteins. The "lids" on the sodium gates will be scripted to pop open to let Na+ ions through while the bottoms of the K+ channels will flip open and closed.

The oval shaped guy on the right is part of a Na+/K+ pump.

All these proteins are embedded in a stylised plasma membrane (red fatty acid residues connected to white polar heads with phosphorus for the phospholipids).

This project is actually part of a planned metabolism build which uses the neuron to illustrate how cells use active and passive transport for complex processes. So it's not meant as a full action potential simulation though my scripting strategy will take that possibility into account.

Sunday, April 5, 2009

Fret no more!

When at the Best Practices conference several presenters beefed about having to face the slide viewers in use to advance their slides.

Well, heated discussions of the merits of slide presentations in SL aside, I modified my simple viewer discussed in my last post to take care of this problem. So fret no more SL conference presenters because now there is Simone's absurdly simple minimalist podium slide viewer/podium! (AKA Silly viewer)

It consists of a big viewer for the audience and a small viewer that the present er can use to control the slides while facing the audience! All you do is transfer your slide textures from you inventory to the inventory of both the big and small viwers and you are good to go.

I haven't tested it on big sets of slides so I don't know how Erich Bremer'sbuffering system will work with big sets. But it took about 5 minutes last night to whip this together (with a last minute change tonight). By the way I did not start out to make this viewer but it was a proof of concept to myself of another project, namely to update my clunky image map type viewer used in my photosynthesis build. More later.

The picture shows my male AV, Simeon Gateaux who has his own land next to mine and he tests permissions etc.

So if you think my silly little viewer might be of use to you (you can resize and move both prims), you can IM me, Simone Gateaux, in SL or stop by my garden spot (SLurl) in Carmine and grab a copy to try and a note card. It's free but both feedback and donations toward my private tier are accepted.

All you have to do (and this is changed from my desription in SLED BTW, is rez the viewer and insert your slides in the right order (careful here SL will put them in alpha order) into the "podium", resize the main viewer, position the podium and you are ready. Do not mess with the blacked out parts of the prims. They hide the buffered textures.

Wednesday, April 1, 2009

Evolution I: Simulating genetic drift with Caminalcules

So far I been working with my caminalcules in terms of genetics. But of course-and maybe someone ought to tell creationists about this-evolution and genetics are logically connected and evolution follows from genetics. So naturally I want to use my system to simulate the basic mechanisms of evolution.

Yesterday and today I programed a prototype Evolver (pink square) that simulates genetic drift. Genetic drift is an agent of evolution where a population's genetic make up changes due to sampling error. Drift is particularly important for small populations, such as caminalcule populations which given the prim limits in SL can never be very big.

Genetic drift is actually easier to simulate than natural selection, so it makes a good starting point for scripting and probably also for students to play with.

To look at populations of caminalcules I treat the population as a list containing the genotypes of all the individuals in the population. I use the same phenotype routines developed for genetics crosses and simply can access the approriate caminalcule through the list index.

Next I had to write a series of population functions:

string randommating(list the_pop) chooses two individuals from the population at random to mate and produces one offspring.

initialise(integer popsize) produces an initial random population and stores it in a list called start_pop_list and returns that list after rezzing an offspring:

Here's a snippet form this function:

start_pop_list = start_pop_list + genotype;
pass2offspring = (integer)genotype;
llRezObject("bigpup",llGetPos()+<2.0-llfrand(4),2.0-llfrand(4),0>,<0,0,0>,<0,pi/4,0,0>, pass2offspring);
}
while (++icount
return start_pop_list;

Most of the other routines are functions made before for the Caminalcule genetics module. So there is nothing new here. The simulation is direct in that I do not calculate allele frequencies and sample from that.

Doing random mating is pretty easy and here is the new function that handles that:

string randommating(list the_pop)
{
integer index;
string organism1;
string organism2;
string thezygote;
string gamete1;
string gamete2;
integer pop_size = llGetListLength(the_pop);
index = irandom(0, pop_size-1);
organism1 = llList2String(the_pop,index);
gamete1 = make_a_gamete(organism1);
index = irandom(0, pop_size-1);
organism2 = llList2String(the_pop,index);
gamete2 = make_a_gamete(organism2);

//----pick 2 organisms at random to mate from the_pop, self mating allowed----
//list the_pop must have been checked!


return make_zygote_string("4",gamete1, gamete2);
//4 because we assume independence here
}


Well so what happens with genetic drift? I want to write routines to quantitatively track what happens, but for many situations running the drift script for for a number of trials ought to get the idea across so here are some pictures from two sets of runs.

My first run started with a population that looked like this:


Four generations later...

Notice the pink and green phenotypes are becoming more common. The the genes related to the white caminalcules have apparently been eliminated. Since the genes related to the white photype are recessive the student might think (as did some geneticicts in the early 20th century) that the recessive allele ought to dissappear over time any way.

By the 11th generation all you have are these caminalcules:

Actually the picture shows the population after 14 generations since I wanted to make sure the other types were eliminated. This nicely shows that the effect of genetic drift is to reduce genetic variation in a population.

Now consider a trial starting with this population:

Not very different than the starting population from the previous run. But look what happens now! This is at generation 10. Note the large number of white caminalcules. Remember white is recessive.



And by generation 15:


Only the white caminacules are left and it looks like only one type of spotting! This illustrates two points. First of all as I noted earler, recessive alleles are not eliminated just because they are recessive, but evolution is strongly contingent. Just because you get one result one time, the chance elements in evolution such as genetic drift may cause completely different out comes the following time. This can lead students and teachers into all sorts of interesting avenues of thinking about how evolution works!

If you want to see how this works, look for me in world.

Hopefully later this week I will have worked through natural selection.






Friday, March 27, 2009

Caminalcules Spotted at Genome Island!

No need to panic. I sent Max Chatnoir a pair of them for her to break as a beta tester, which she very nicely did in about 1 minute. So made some changes based on her feedback. The Caminalcules can now do various modes of inheritance and can either mate with each other of self fertilize as any proper organism for genetic studies ought to be able to do. Did I mention they also do linked genes? The picture show Max with her first brood. There had been a problem with permissions which caused a bit of grief until I tracked the problem down.






This coming week will see lots of frantic designing and building for the Caminalcule project including plans for a build on Genome Island once the prototype build is finished at Carmine. But a good part of today and Saturday I will be at the Virtual World best Practices Conference. Oops! Starting in about 10 minutes.

Friday, March 6, 2009

A handy little string function...

For the Caminalcule project I'm finding it easier to represent a genotype as a string because I can easily manipulate strings. But LSL is not real whippy on the string manipulation front.One function I needed was one that would substitute a sub-string starting at a certain position in an original string without making any other changes in the original string.

There are functions that do similar things but they rely on having a recognizable set of characters in the original string as in standard find and replace. But what I wanted was a function that goes to a particular position in the original string where I (or a script) specify where the position starts.

This is important for me because the way I represent genotypes there are some things that change a lot, but somethings may not change very often and yet I want to keep those things together with the more variable stuff-kind of like what happens in a chromosome.

So if I have two sentences:

"The sly big fox is learning scripting." and

"The big sly cat is learning scripting" ,

I might want to change what ever starts at letter 9 with the substring "red". Hence my little function:

replace_string(string original,string sub_string,integer pos).

Try copying the following code and inserting it in to a prim and let me know what you think. Given Blogger's tendency to mess up LSL code, you might have to change a few things by hand. Or IM me (Simone Gateaux) in world and I will send the script to you.


//begin code here
string replace_string(string original,string sub_string,integer pos)
//replaces part of string starting at pos with substring; does not change the original string length
//real handy for me
{

integer orig_length;
integer length;
string new_string;
length = llStringLength(sub_string);
orig_length = llStringLength(original);
if ((orig_length-1) > pos &&( pos >= 0))
{

new_string = llInsertString(original,pos,sub_string);
new_string = llDeleteSubString(new_string,pos+length, pos+length -1+length);

}
else new_string = original;
return new_string;

} //end function

default
{

touch_start(integer num_detected)
{
string newstring;
string oldstring = "The sly big fox is learning how to script.";
string replacement = "red";
integer position = 8; //position start at 0 index so here 8 is the start of "big"
newstring = replace_string(oldstring,replacement,position);
llWhisper(DEBUG_CHANNEL,oldstring);
llWhisper(DEBUG_CHANNEL,newstring);
}
}
//end code



Thursday, February 26, 2009

Caminalcules II: Mother and her pups

Continuing along with my Caminalcule genetics activity...

Here is a heterozygous Caminalcule mother with 10 of her pups produced by selfing under incomplete dominance. The maternal script produces two gametes at random, the "pup" is rezzed and the genotype along with the degree of dominance communicated to the pup and the pup then changes phenotype.

This is of course not the way it works in the real world; the pups should be rezzed with the genotype in place but there doesn't seem to be an easy way to do that save maybe with some really clever use of llSetPrimativeParams. But my approach seems more flexible.


Here notice that roughly half the "pups" have the heterozygote's phenotype (grey) and roughly half are one of the two phenotypes (black or white) of the homozygotes.

Right now I represent a gene's locus with an SL vector type. The third position is not currently used but it could be used to store some other type of float type information related to the gene say something about its linkage position along a chromosome.

Coming up soon...Caminalcules make nookie.


Tuesday, February 17, 2009

Photosynthesis Engine V....more nitty gritty...

Well the sensor approach outlined last time had some problems. The entire light reaction model has 18 prims. Sensors are limited to the 16 prims closest to the sensor. When the model was running, some of the parts were not conststantly sensing where they needed to go.

So this meant a rework using linked prims and learning about how to get linked prims to communicate.




The big issue was my protons which are rezzed at various times. The problem is that when they are rezzed, they are unlinked prims and so can't communicate with the rest of the model using the link communication functions.

The strategy that worked was to first rezz a proton, then have the linked prim that rezzed the proton get the keys for the required places the protons need to go to and sending that information to the newly rezzed prim using llWhisper functions and listen events in the proton. I was concerned that the proton's listen events might not pick up all the Whispers, but that doesn't seem to be an issue.

The model runs much more smoothly as well!

So come on over and visit at:
http://slurl.com/secondlife/Carmine/118/143/296

Still trying to decide the best way to present the Calvin cycle....and working on some other other goodies. I will also be commenting on the Stepping into Science workshop I attended In World last Friday.

Tuesday, December 9, 2008

Simone's Simple Scripts #1

One of my pre-sabbatical tasks is to learn the scripting lanquage. So I am starting a new occasional feature Simone's Simple Scripts to share some scripts and amuse more advanced scripters with my fumbling around.

A useful tool in Second Life is a viewer that visitors to flip through textures or text-the holy grail of course is true web on a prim where users could essentially use a prim as a web browser, thus bringing the web into Second Life. Failing that, a standard thing to do is display information as textures and flip through that and there are of course lots of such viewers out there.

Prowling around the SL scripting portal I found a really cool and new function, llDetectedTouchFace(i). This function detects what face of a prim you are touching. Now this has possibilities. So I decided to make a simple viewer that uses only one prim and real simple controls. I like simple.

So I tool a box prim, flattened it out so that the central face is a display and the left and right faces are for flipping through images-which could be text captured as a texture of course.

The accompanying picture shows the result:

The script is pretty simple.

Unfortunately Blogger seems to mangle SL script.
So if you want a copy of my one prim viewer that you can copy and modify contact me in world (Simone Gateaux) or e-mail me. sgateaux at gmail dot com and I will send you the script or if you want, in world give you a copy of the one prim viewer.

Of course feedback and suggestions are always welcome.

P.S. If any one has an idea how to stop Blogger from mangling SL code...let me know.