Extracting blocks of data after fix step from Molecular Dynamics - extract

I am newbie in bash programming. My problem is the following:
I have a trajectory file in xyz extension, out of a molecular dynamics calculation. In this file there are, more or less, 2000 blocks of coordinates. Each block of coordinate start with the number of atoms and end with the same number of atoms reported, e.g. of a block:
352 (starting point first block)
i = 0,
...
...
352 (ending point first block/starting point second block)
i = 10,
...
...
352
out of this file, I would like to be able to grep some of the blocks/configurations along the all trajectory file, at a fix ratio, lets say, every 10 configurations ( so that in the end I have 200 sampled structures from the beginning to the end of the trajectory file).
I thought, but again, I am not an expert, to use a for loop like:
for i in .xyz
do (grep "352
\n.*some_pattern.*
\n.*352");
done
The point is that I have no idea on 1st how to tell the script to grep the block and 2nd to extract the blocks every 10 configurations.
Can you kindly help me?
P.S. while for the first point I think after sometime I will be able to fix it, the second is the most annoying.

Related

Pygame: how to load 150 images and present each one for only .5sec per trial

I'm currently trying to develop a psychology experiment which involves having 150 .tif images that need to be presented for 0.5sec per trial, full screen, after a noise has been heard. Each image needs to be presented at least once before being presented again. I am completing my experiment within pygame.
I've been thinking about saving all the images into a directory and then pulling them each out one by one. Does this seem like a good idea?
I'm very new to programming and would appreciate any help/links to similar questions. If I'm missing any relevant information please let me know.
Thank you!
Use the glob module to get a list of your image filenames: https://pymotw.com/3/glob/index.html
Loop over this list of filenames, load them with pygame.image.load and append the resulting images/pygame.Surfaces to a list.
Shuffle the list, create an index variable (index = 0) and assign the image at the current index to another variable, e.g. current_image = image_list[index].
Use a timer variable to increment the index and swap the image after the desired time interval check out the pygame.time.get_ticks, set_timer or delta time solutions here.
If the index is >= the length of the list, reset it to 0 and shuffle the list again.

Set time for one tick mark in cesium

Is there a way to set how much time one tick mark on the time line in Cesium is equal to? I know viewer.timeline.zoomTo() sets the time range for the whole timeline.
There's no public API for this, but if you're OK with a little hacking, you can find this answer in local variable tinyTic in Timeline.js around line 490. The line I've identified here is just a blank line between two sections of code: the code above this line is the last bit of logic to modify tinyTic (possibly resetting it to minSize on line 485), and then on line 493 you can see tic = getNextTic(tic, tinyTic) being used to generate the smallest tics.
You could, for example, add a line of code on L490 that saves the value of tinyTic to some object that you can access from outside code. The value here is measured in seconds (so 5 means 5 seconds, 300 means 5 minutes, etc).

Octave specgram generates two diffent answers

I have a project where I have to recognize the frequency from an audio file. For this I use a single tone of 10 kHz to see if I can get it working.
Since I am pretty new to Octave, I tried this example with my own audio file.
I tried to understand what happens by doing some research to all functions.
My question here is; if I let specgram plot the figure when I do not specify it's output:
specgram(y,fftn,Fs,hanning(window),step);
it gives a line at 10kHz which is what I want.
But if I specify the output for the specgram function
[S,f,t]= specgram(y,fftn,Fs,hanning(window),step);
and let it plot, it plots the line at 18 kHz.
I figured it have to be in the inputs for the figure and I tried modifying these a bit, but every time I do that Octave gives an error.
I need the frequency as an given output, since I have to do some calculations with it, I figured I need to specify the frequency output.
This is the part of the code that specify the plot for the spectrogram:
step= fix(5*Fs/1000); % stepsize of the window
window= fix(90*Fs/1000); % window size
fftn =2^nextpow2(window); % Size of the FFT block
[S,f,t]= specgram(y,fftn,Fs,hanning(window),step);
S= abs(S(2:fftn*12000/Fs,:)); % Normalize the phase
S= S/max(S(:)); % Normalize the Energy
S= max(S, 10^(-40/10)); % Throw out values below -40 dB and above -3dB
S= min(S, 10^(-3/10));
figure
imagesc(t,f,(log(S)));
Can anyone help me here how to gain the frequency data from the audio file so I can use it in some calculations?
I have searched for answers already in the Octave manual for help and I tried it with various matlab sites. Also checked already many posts here such as:
How does Octave spectrogram 'specgram' from signal work?
Methodology of FFT for Matlab spectrogram / short time Fourier transform functions
P.S. Sorry for my bad English, it's not my native language
I found the answer myself, it turns out it is in this line of code:
S= abs(S(2:fftn*12000/Fs,:));
if I delete this line, the lines are placed on the right frequency in the figure. To me it looks like this line just takes a small space of the fft and replaces it with other frequencies but I'm not shure about that.

Encoding paths in a graph as strings?

Suppose I have a DAG and, rather than using a graph db, the paths are encoded as {id:"node3", path:"node0|node1|node2"} to represent that node3 can reach node0 via node2 then node1. Would it be a good idea to encode the path in a string if reads are not frequent? The paths generally don't contain more than 50 nodes each.
Thanks
I think that you will find that your approach won't work as well as you want. One of the properties that makes graphs interesting are the combinatorial explosions that can occur from their structures. Storing every path for every node is going to get big very fast and I think it would cease to scale and do what you expected.
Consider the following blog posts:
http://thinkaurelius.com/2012/04/21/loopy-lattices/
http://thinkaurelius.com/2013/06/12/loopy-lattices-redux/
The posts explore path counting on 20x20 directed lattice. It finds that a graph "with only 441 vertices and 840 edges, has over 137 billion unique directed paths."

AS3 repeat same code in a vertor which has 2500 objects

This is my problem, i'm making a path finding program 'jump point search algorithm'. And i need to reset every node (object) in the vector 40 by 40 vector so 2500 nodes, so i need to do the following
//* some type of loop*//
{
node.is_been_on = false;
}
But my path finding may happen 5 times every seconds with a few objects. So that a lot of looping.
What is the CPU friendly way to do this, or another solution which means i don't need to do it.
One of my friends saying that i should make a 40 by 40 boolean array and having the is_been_on variable it, so i would refer to that and not the node, would that be better?
Thanks for reading, and i hope you can help
The most simple idea is to reset only the nodes that you've changed - store them in different array and iterate only it - JPS should modify only a small part of the given nodes.
The idea of your friends is not better, since you will still iterate over all nodes, and modify each value. The values of the node are also boolean (or at least I hope so), so you win nothing but having second array (vector) of values.
Either way I don't find it that bad to modify bool values, but if you really need to optimize (which I find great) - go with "reset what's changed" - can't imagine better one.
But why do you recalculate path 5 times every second? You have graph with a size 40x40, by the help of A* or another one algorithm, you will be able find correct path. As you calculate path, you don't recalculate it again, only if you have dynamic obstacles in the game.
If you don't know how to implement pathfinding algorithm in AS3 project. There are several ready solutions