Commit 094922ad authored by Thorsten Auth's avatar Thorsten Auth
Browse files

Initial commit. Python script that submits metadata to the test version of...

Initial commit. Python script that submits metadata to the test version of SampleDB for the action for filament-motor simulations. The metadata is read from a text file that can be specified as first argument. If also a second argument "-1" is provided, the script will perform a consistency check for the metadata only. Furthermore, the script uploads the files "parameters.ini" and "fixparameters.cpp" for that the paths are hardcoded and have to be adjusted before execution.
parents
#ifndef FIXPARAMETER_CPP
#define FIXPARAMETER_CPP
#include <cmath>
#include "boostrandomwrapper.cpp"
#include "inifile.cpp"
// POTENTIAL:
// 0 -> lennard jones
// 1 -> yukawa
// 2 -> Separation-Shifted Lennard-Jones Potential (SSLJ)
#define POTENTIAL 2
// don't modify these:
#if POTENTIAL == 0
//#define CUTOFF (1.122462048309373) //the classic cutoff, the minimum of the original LJ potential, r=2^(1./6).
#define CUTOFF (0.396763) // This is our desired cutoff, equal to SSLJ minimum with alpha=1.05. We set it to compare LJ results to SSLJ.
#define LJMIN (1.122462048309373) // minimum of the original LJ potential, r=2^(1./6).
#define SCALING (CUTOFF/LJMIN) //we scale r (distance) to move the minimum of LJ potential to our desired CUTOFF
#define SCALING7 (SCALING*SCALING*SCALING*SCALING*SCALING*SCALING*SCALING)
#define SCALING13 (SCALING*SCALING*SCALING*SCALING*SCALING*SCALING*SCALING*SCALING*SCALING*SCALING*SCALING*SCALING*SCALING)
#define ENERGY_CONST 1
#endif
#if POTENTIAL == 1
#define CUTOFF (2.0)
#define YUKAWAA (18000000)
#define YUKAWAB (16.39)
#define ENERGY_CONST 1
#endif
#if POTENTIAL == 2
#define SSLJ_ENERGY 0.03
#define ALPHA 1.05 //(exp(1./6.*log(2./(SSLJ_ENERGY-1)*(sqrt(SSLJ_ENERGY)-1))))
#define CUTOFF ( sqrt(exp(1./3.*log(2.))-ALPHA*ALPHA) ) //this cutoff is exactly where the potential has its minimum
#define ENERGY_CONST (SSLJ_ENERGY/( 4*pow(1./ALPHA,6)*(pow(1./ALPHA,6)-1)+1 ) ) // ENERGY_CONST goes in front of force. We tune it here to give us the desired energy barrier for two intersecting rods
#endif
#define RODCUTOFF (RODLENGTH*BEADLENGTH+CUTOFF)
#define MINCELLSIZE ceil(RODCUTOFF)
#define INITPARADISTANCE 1.5 //initial distance between parallel rods (for the 'checkboard' and 'parallel' initial conditions)
//INITSTATE (initial state):
// 0 -> parallel
// 1 -> checkboard
// 2 -> random with overlap (For capped potentials like SSLJ, blows up for e.g. Lennard-Jones potential)
#define INITSTATE 2
#define BEADLENGTH CUTOFF
#define ASPECTRATIO 18//based on this value, you should set RODLENGTH by hand to 'floor(CUTOFF*ASPECTRATIO/BEADLENGTH + 0.5)'
#define RODLENGTH 18// this is not the physical length of rod; it's the number of beads in a rod. For physical length of the rod, look at RODL in the next line. For technical reasons, I cannot set the proper value for this automatically. It should be put here explicitly by hand. If a wrong value is here, the code will complain and will tell which value you should put in. The complain message is inside 'output.cpp'.
#define RODL (BEADLENGTH*RODLENGTH) //the real 'length' of the rod
#define RODAREA (RODL*CUTOFF)
// user-modifiable
//#define DELTAT 0.001
#define DELTAT 0.01
#define VOLUMEFRACTION 0.1
#define DENSITY (1.0*VOLUMEFRACTION/RODAREA) //this is number density; number of rods per area
#define NRODS 10 //int(SYSSIZE*SYSSIZE*DENSITY)
#define LINCELLS 4
#define THREADS 4
#define CELLSIZE MINCELLSIZE
#define MAXRODSPERCELL (RODLENGTH+3)
// Attention: MAXRODSPERCELL does not guarantee that you can put MAXRODSPERCELL rods in one cell, it just tells the program to allocate so much memory, that this number of rods could be stored in one cell
#define PECLET 200
#define CORRELATION_RESOLUTION 100
#define CORRELATION_DOMAIN (20.0*RODLENGTH*BEADLENGTH)
#define CORRELATION_DELTA (CORRELATION_DOMAIN/CORRELATION_RESOLUTION)
#define DPDINTERACTION true
#define DPDGAMMA 10
// don't modify these again:
#define BEADLENGTH6 BEADLENGTH*BEADLENGTH*BEADLENGTH*BEADLENGTH*BEADLENGTH*BEADLENGTH
#if RODLENGTH % 2 == 0
#define EVENBEADS 0.5
#else
#define EVENBEADS 0.0
#endif
#define SYSSIZE (LINCELLS*CELLSIZE)
#define SYSSIZED static_cast<double>(SYSSIZE)
#define DRIVE_FORCE (DELTAT*SIGMA02/2/RODL * PECLET) //(0.559154*PECLET/200)//(1.21*ENERGY_CONST/static_cast<double>(RODLENGTH*BEADLENGTH))
/* By Masoud, put here on 03.02.2012
* First, in readable form:
* noise_variance_par = 2 F L²/ Pe / dt
* noise_variance_perp = 2 * 2 F L²/ Pe / dt
* noise_variance_rot = 2 F L²/ Pe / dt / 12 * L²
* Then, the same relations in the language of the code:
* (Note that variable 'Noise_variance' below is actually the SQUAREROOTS of the noise variances)
*
*/
#define SIGMA02 3.9933
const double Noise_variance[] = { sqrt( SIGMA02 * RODL ),
sqrt( 2 * SIGMA02 * RODL ),
sqrt( SIGMA02 * RODL*RODL*RODL /12. ) };
//const double Noise_variance[] = { sqrt( 2*DRIVE_FORCE * (RODLENGTH*BEADLENGTH)* (RODLENGTH*BEADLENGTH) / (PECLET) / (DELTAT) ),
// sqrt( 2 * 2*DRIVE_FORCE * (RODLENGTH*BEADLENGTH)* (RODLENGTH*BEADLENGTH) / (PECLET) / (DELTAT) ),
// sqrt( 2*DRIVE_FORCE * (RODLENGTH*BEADLENGTH)* (RODLENGTH*BEADLENGTH) / (PECLET) / (DELTAT) /12. * (RODLENGTH*BEADLENGTH) * (RODLENGTH*BEADLENGTH) ) };
// gamma is the friction coefficient, and what follows is inverse gamma, for different components (parallel, prependicular, and rotational):
const double Invgamma[] = { 1.0/static_cast<double>(RODLENGTH*BEADLENGTH),
1.0/static_cast<double>(2*RODLENGTH*BEADLENGTH),
6.0/static_cast<double>(RODLENGTH*RODLENGTH*RODLENGTH*BEADLENGTH*BEADLENGTH*BEADLENGTH) };
inifile* ini;
int iniset;
typedef brgwrap<double> rg_c;
typedef unsigned int uint;
struct iniparameter_c {
inifile* ini;
int iniset;
int totalsteps;
int steps2equilibrate;
int write_after_steps;
string filename_pref;
int halt_after_seconds;
bool loadtrigger;
string loadstatefile;
iniparameter_c() : loadtrigger(false) {}
void loadparams() {
totalsteps = ini->getlng("totalsteps", 1000, iniset);
steps2equilibrate = ini->getlng("steps2equilibrate", 0, iniset);
write_after_steps = ini->getlng("write_after_steps", totalsteps/100);
filename_pref = ini->getstr("filename_prefix", "default", iniset);
halt_after_seconds = ini->getlng("halt_after_seconds", 40000, iniset);
}
};
// constants read from ini file:
iniparameter_c ip;
#define WRITE_VMD_ANIM false//if we should record animation (xyz) file to be used by VMD.
#define WRITE_MINIMAL_DATA true//if we should record rods' data in the form "x y theta" to be later used by some other visualization program, like gnuplot.
#define FRACTION_TO_DRAW 1//if we want to write all rod positions (in this case =1), or a fraction of them (like 10% of them, =0.1). This is to make the output file smaller and easier to visualize.
#define SHOULD_MARK_INTERSECTIONS false //if we also want to save the point of intersection for rods (doesn't work perfectly)
#endif // FIXPARAMETER_CPP
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
sdb:
This script submits Gerrit's simulation parameters that are stored in a text
file to SampleDB.
@author: Thorsten Auth
Created on 14 April 2021.
"""
import sys
import csv
from mergedeep import merge
import requests # https://www.jetbrains.com/help/pycharm/configuring-python-interpreter.html#packages
import base64
# import json
api_token = '5f1734e647083dd144db57d30c9d947d4ad76845b97728e6dddc308840cc3a7a'
def decomment(csvfile): # Allow comment lines starting with # in metadata file.
for rowcsv in csvfile:
raw = rowcsv.split('#')[0].strip()
if raw:
yield raw
def is_number(string): # Check if input is a number.
try:
float(string)
return True
except ValueError:
return False
# Check whether the number of arguments is correct. Up to two arguments are allowed:
# sdb arg1 arg2
# arg1: input file
# arg2: If set to -1 only checks the data consistency without actually submitting it to SampleDB.
if len(sys.argv) < 2:
print('Error: Metadata file name not provided.', file=sys.stderr)
sys.exit(1)
if len(sys.argv) > 3:
print('Error: Too many arguments provided.', file=sys.stderr)
sys.exit(1)
try:
csv_file = open(str(sys.argv[1]))
except IOError:
print('Error: Metadata file not found.', file=sys.stderr)
sys.exit(1)
concheck = 0
if len(sys.argv) > 2:
if str(sys.argv[2]) != "-1":
print('Error: Second argument can only be -1.', file=sys.stderr)
sys.exit(1)
else:
print('Warning: Parameter consistency check only! No data submitted to SampleDB.')
concheck = -1
read_csv = csv.reader(decomment(csv_file), delimiter=";")
properties = ["project", "action_id", "name", "created", "description", "boundary_conditions", "nfil", "nseg", "nmot",
"l", "sm", "a0", "k", "kappa", "ka", "kappab", "boxx", "boxy", "r", "phi", "km", "r0m", "ron", "roff",
"p0m", "dt", "alpha", "nsteps", "nsamp", "tdif_min", "tags"]
required = ["project", "action_id", "name", "created", "boundary_conditions", "nfil", "nseg", "nmot",
"l", "sm", "a0", "k", "kappa", "ka", "kappab", "boxx", "boxy", "r", "phi", "km", "r0m", "ron", "roff",
"p0m", "dt", "alpha", "nsteps", "nsamp", "tdif_min", "tags"]
optional = ["description"]
# Read metadata file, check for duplicates, remove empty lines and tabs.
duplicates = set()
parameters = {}
for row in read_csv:
if any(field.strip() for field in row): # Skips empty rows in input file.
row = list(filter(None, row))
row = [
field.replace("\t", "").strip()
for field in row
if field.strip()
]
if row:
if row[0] in parameters:
duplicates.add(row[0])
print("Identifiers that are present more than once are:", row[0], file=sys.stderr)
parameters[row[0]] = row[1]
if len(duplicates) == 0:
print('Parameters read without duplicates.')
else:
print('Error: The metadata file contains multiple entries with the same indentifiers.', file=sys.stderr)
# Make double sure that the medatata file provides the date when the simulation has been performed.
if "created" not in parameters:
print('Error: The creation date is missing in the metadata file.', file=sys.stderr)
sys.exit(1)
# Check whether all properties that are required for the system are present in the metadata file.
missing = set(required) - set(parameters)
for x in missing:
print('Error: The metadata file does not contain the required property ' + x + '.', file=sys.stderr)
if missing:
sys.exit(1)
# Indentify other parameters.
other = set(parameters) - set(required)
for x in other:
print('Additional parameter: ' + x + '.')
print('Metadata file read without errors.')
if concheck == -1:
sys.exit(0)
else:
print('Submitting metadata to SampleDB...')
tagsin = list()
tagsin.append(parameters['tags'].split(","))
# Define dictionary literal for mandatory parameters.
data = {
"action_id": int(parameters['action_id']),
"data": {
"name": {
"_type": "text",
"text": parameters['name']
},
"created": {
"_type": "datetime",
"utc_datetime": parameters['created']
},
"tags": {
"_type": "tags",
"tags": tagsin[0]
},
"project": {
"_type": "object_reference",
"object_id": int(parameters['project'])
},
"boundary_conditions": {
"_type": "text",
"text": parameters['boundary_conditions']
},
"nfil": {
"_type": "quantity",
"units": "1",
"dimensionality": "dimensionless",
"magnitude_in_base_units": float(parameters['nfil'])
},
"nseg": {
"_type": "quantity",
"units": "1",
"dimensionality": "dimensionless",
"magnitude_in_base_units": float(parameters['nseg'])
},
"nmot": {
"_type": "quantity",
"units": "1",
"dimensionality": "dimensionless",
"magnitude_in_base_units": float(parameters['nmot'])
},
"l": {
"_type": "quantity",
"units": "1",
"dimensionality": "dimensionless",
"magnitude_in_base_units": float(parameters['l'])
},
"sm": {
"_type": "quantity",
"units": "1",
"dimensionality": "dimensionless",
"magnitude_in_base_units": float(parameters['sm'])
},
"a0": {
"_type": "quantity",
"units": "1",
"dimensionality": "dimensionless",
"magnitude_in_base_units": float(parameters['a0'])
},
"k": {
"_type": "quantity",
"units": "1",
"dimensionality": "dimensionless",
"magnitude_in_base_units": float(parameters['k'])
},
"kappa": {
"_type": "quantity",
"units": "1",
"dimensionality": "dimensionless",
"magnitude_in_base_units": float(parameters['kappa'])
},
"ka": {
"_type": "quantity",
"units": "1",
"dimensionality": "dimensionless",
"magnitude_in_base_units": float(parameters['ka'])
},
"kappab": {
"_type": "quantity",
"units": "1",
"dimensionality": "dimensionless",
"magnitude_in_base_units": float(parameters['kappab'])
},
"boxx": {
"_type": "quantity",
"units": "1",
"dimensionality": "dimensionless",
"magnitude_in_base_units": float(parameters['boxx'])
},
"boxy": {
"_type": "quantity",
"units": "1",
"dimensionality": "dimensionless",
"magnitude_in_base_units": float(parameters['boxy'])
},
"r": {
"_type": "quantity",
"units": "1",
"dimensionality": "dimensionless",
"magnitude_in_base_units": float(parameters['r'])
},
"phi": {
"_type": "quantity",
"units": "1",
"dimensionality": "dimensionless",
"magnitude_in_base_units": float(parameters['phi'])
},
"km": {
"_type": "quantity",
"units": "1",
"dimensionality": "dimensionless",
"magnitude_in_base_units": float(parameters['ka'])
},
"r0m": {
"_type": "quantity",
"units": "1",
"dimensionality": "dimensionless",
"magnitude_in_base_units": float(parameters['r0m'])
},
"ron": {
"_type": "quantity",
"units": "1",
"dimensionality": "dimensionless",
"magnitude_in_base_units": float(parameters['ron'])
},
"roff": {
"_type": "quantity",
"units": "1",
"dimensionality": "dimensionless",
"magnitude_in_base_units": float(parameters['roff'])
},
"p0m": {
"_type": "quantity",
"units": "1",
"dimensionality": "dimensionless",
"magnitude_in_base_units": float(parameters['p0m'])
},
"dt": {
"_type": "quantity",
"units": "1",
"dimensionality": "dimensionless",
"magnitude_in_base_units": float(parameters['dt'])
},
"alpha": {
"_type": "quantity",
"units": "1",
"dimensionality": "dimensionless",
"magnitude_in_base_units": float(parameters['alpha'])
},
"nsteps": {
"_type": "quantity",
"units": "1",
"dimensionality": "dimensionless",
"magnitude_in_base_units": float(parameters['nsteps'])
},
"nsamp": {
"_type": "quantity",
"units": "1",
"dimensionality": "dimensionless",
"magnitude_in_base_units": float(parameters['nsamp'])
},
"tdif_min": {
"_type": "quantity",
"units": "1",
"dimensionality": "dimensionless",
"magnitude_in_base_units": float(parameters['tdif_min'])
},
"other_parameters": [
{
"name": {
"_type": "text",
"text": "nves"
},
"value": {
"_type": "text",
"text": "2"
}
},
{
"name": {
"_type": "text",
"text": "timestep"
},
"value": {
"_type": "text",
"text": "7.8"
}
},
{
"name": {
"_type": "text",
"text": "3rdparam"
},
"value": {
"_type": "text",
"text": "93"
}
}
]
}
}
# Define dictionary literals for optional predefined parameters and merge them with the original dictionary.
if "description" in parameters:
dictoptional = {
"data": {
"description": {
"_type": "text",
"text": parameters['description']
}
}
}
merge(data, dictoptional)
# Define dictionary literals for optional other parameters and merge them with the original dictionary.
addopt = set(other) - set(optional)
if addopt:
dll = []
for x in addopt:
dictoadd = {
"name": {
"_type": "text",
"text": x
},
"value": {
"_type": "text",
"text": parameters[x]
}
}
dll.append(dictoadd)
dopt = {}
dopt['data'] = {}
dopt['data']['other_parameters'] = dll
merge(data, dopt)
r = requests.post(
"https://docker.iff.kfa-juelich.de/dev-sampledb/api/v1/objects",
# "https://docker.iff.kfa-juelich.de/dev-sampledb/api/v1/objects/2927/versions/",
json=data,
headers={"Authorization": "Bearer " + api_token}
)
print(r.status_code)
print(r.content)
print(r.headers["Location"])
object_id = r.headers["Location"].split('objects/')[1].split('/')[0]
user_id = 70
r = requests.put(
f"https://docker.iff.kfa-juelich.de/dev-sampledb/api/v1/objects/{object_id}/permissions/users/{user_id}",
json="grant",
headers={"Authorization": "Bearer " + api_token}
)
print(r.status_code)
group_id = 10
r = requests.put(
f"https://docker.iff.kfa-juelich.de/dev-sampledb/api/v1/objects/{object_id}/permissions/groups/{group_id}",
json="grant",
headers={"Authorization": "Bearer " + api_token}
)
print(r.status_code)
file_name = '/users/biosoft/Dropbox/simulations/sravya/va040_t03/parameters.ini'
# file_content = b'Example Content'
file_content = open(file_name, 'rb').read()
r = requests.post(
f"https://docker.iff.kfa-juelich.de/dev-sampledb/api/v1/objects/{object_id}/files/",
json={
"storage": "local",
"original_file_name": file_name,
"base64_content": base64.b64encode(file_content).decode('ascii')
},
headers={"Authorization": "Bearer " + api_token}
)
print(r.status_code)
file_name = '/users/biosoft/Dropbox/Archive/180506/masoud/spp/code/qr4.0/fixparameters.cpp'
# file_content = b'Example Content'
file_content = open(file_name, 'rb').read()
r = requests.post(
f"https://docker.iff.kfa-juelich.de/dev-sampledb/api/v1/objects/{object_id}/files/",
json={
"storage": "local",
"original_file_name": file_name,
"base64_content": base64.b64encode(file_content).decode('ascii')
},
headers={"Authorization": "Bearer " + api_token}
)
print(r.status_code)
[0]
totalsteps=300000000000000
write_after_steps=20000
filename_prefix=sslj000
halt_after_seconds=85000
steps2equilibrate=0
[1]
totalsteps=400
write_after_steps=1
filename_prefix=sslj000
filename_prefix_mem=sslj000_mem
halt_after_seconds=30
[2]
totalsteps=800000000
write_after_steps=200
filename_prefix=sslj000
filename_prefix_mem=sslj000_mem
halt_after_seconds=5
project ; 2927
action_id ; 73
name ;Filaments and motors
description ; This entry was created using the HTTP API.
created ; 2020-11-10 01:02:03
tags ; demo,simulation,ibi5
boundary_conditions ;Periodic boundary conditions
#Boundary conditions ;Channel
#Boundary conditions ;Rigid circular confinement
nfil ; 895; Nr. of filaments
nseg ; 21; Nr. of beads per filament
nfil2 ; 895; Nr. of filaments
nseg2 ; 21; Nr. of beads per filament
nmot ; 100; Nr. of motors
l ; 10.000; Filament length
sm ; 0.500; Filament interaction lengt
a0 ; 0.500; Filament bond length
k ; 500.000; Filament spring constant
kappa ; 18.000; Filament bending rigidity
ka ; 1000.000; Area constraint constant
kappab ; 18.000; Boundary bending rigidity
boxx ; 100.000; System size x
boxy ; 200.000; System size y
r ; 75.000; Confinement radius
phi ; 0.150; Area fraction
km ; 1000.000; Motor harmonic spring
r0m ; 0.500; Motor spring length
ron ; 1.800; Motor on length
roff ; 1.800; Motor off length
p0m ; 1.000; Motor step frequency
dt ; 0.005; Integration time step EOM
alpha ; 1.000; Viscosity implicit solvent
nsteps ; 10000000; Simulation length (steps)
nsamp ; 2000; Sampling frequency output
tdif_min ; 10; Sampling frequency msd
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment