Exemplo n.º 1
0
Id ReadKkit::buildTable( const vector< string >& args )
{
	string head;
	string clean = cleanPath( args[2] );
	string tail = pathTail( clean, head ); // Name of xtab

	Id pa = shell_->doFind( head ).id;
	assert( pa != Id() );
	Id tab;

	int mode = atoi( args[ tableMap_[ "step_mode" ] ].c_str() );
	if ( mode == TAB_IO ) {
	} else if ( mode == TAB_LOOP || mode == TAB_ONCE ) {
		tab = shell_->doCreate( "StimulusTable", pa, tail, 1 );
		assert( tab != Id() );
		double stepSize = atof( args[ tableMap_[ "stepsize" ] ].c_str() );
		Field< double >::set( tab, "stepSize", stepSize );
		if ( mode == TAB_LOOP )
			Field< bool >::set( tab, "doLoop", 1 );
		double input = atof( args[ tableMap_[ "input" ] ].c_str() );
		Field< double >::set( tab, "startTime", -input );
		// The other StimulusTable parameters will have to wait till the
		// loadTab is invoked.
	}


	string temp = clean.substr( 10 );
	tabIds_[ temp ] = tab; 

	Id info = buildInfo( tab, tableMap_, args );

	return tab;
}
Exemplo n.º 2
0
/**
 * Build a Stim entry in simulation, i.e., a PulseGen
 */
Id ReadKkit::buildStim( const vector< string >& args )
{
	string head;
	string clean = cleanPath( args[2] );
	string tail = pathTail( clean, head );
	Id pa = shell_->doFind( head ).id;
	assert( pa != Id() );

	double level1 = atof( args[ stimMap_[ "firstLevel" ] ].c_str() ); 
	double width1 = atof( args[ stimMap_[ "firstWidth" ] ].c_str() ); 
	double delay1 = atof( args[ stimMap_[ "firstDelay" ] ].c_str() ); 
	double level2 = atof( args[ stimMap_[ "secondLevel" ] ].c_str() ); 
	double width2 = atof( args[ stimMap_[ "secondWidth" ] ].c_str() ); 
	double delay2 = atof( args[ stimMap_[ "secondLevel" ] ].c_str() ); 
	double baselevel = atof( args[ stimMap_[ "baseLevel" ] ].c_str() );

	Id stim = shell_->doCreate( "PulseGen", pa, tail, 1 );
	assert( stim != Id() );
	string stimPath = clean.substr( 10 );
	stimIds_[ stimPath ] = stim;
	Field< double >::set( stim, "firstLevel", level1 );
	Field< double >::set( stim, "firstWidth", width1 );
	Field< double >::set( stim, "firstDelay", delay1 );
	Field< double >::set( stim, "secondLevel", level2 );
	Field< double >::set( stim, "secondWidth", width2 );
	Field< double >::set( stim, "secondDelay", delay2 );
	Field< double >::set( stim, "baseLevel", baselevel );

	numStim_++;
	return stim;
}
Exemplo n.º 3
0
Id ReadKkit::buildReac( const vector< string >& args )
{
	string head;
	string clean = cleanPath( args[2] );
	string tail = pathTail( clean, head );
	Id pa = shell_->doFind( head ).id;
	assert( pa != Id() );

	double kf = atof( args[ reacMap_[ "kf" ] ].c_str() );
	double kb = atof( args[ reacMap_[ "kb" ] ].c_str() );

	// We have a slight problem because MOOSE has a more precise value for
	// NA than does kkit. Here we assume that the conc units from Kkit are
	// meant to be OK, so they override the #/cell (lower case k) units.
	// So we convert all the Kfs and Kbs in the entire system after
	// the model has been created, once we know the order of each reac.

	Id reac = shell_->doCreate( "Reac", pa, tail, 1 );
	reacIds_[ clean.substr( 10 ) ] = reac; 
	// Here is another hack: The native values stored in the reac are
	// Kf and Kb, in conc units. However the 'clean' values from kkit
	// are the number values numKf and numKb. In the 
	// function convertReacRatesToNumUnits we take the numKf and numKb and
	// do proper conc scaling.
	Field< double >::set( reac, "Kf", kf );
	Field< double >::set( reac, "Kb", kb );

	Id info = buildInfo( reac, reacMap_, args );
	numReacs_++;
	return reac;
}
Exemplo n.º 4
0
/**
 * There is a problem with this conversion, because of the discrepancy of
 * the correct NA and the version (6e23) used in kkit. I take the 
 * concentration as authoritative, not the # of molecules. This is because
 * I use conc units for the rates as well, and to use n for pools and
 * conc for reactions will always introduce errors. This is still not
 * a great solution, because, for example, simulations involving receptor
 * traffic are originally framed in terms of number of receptors, not conc.
 */
Id ReadKkit::buildPool( const vector< string >& args )
{
	string head;
	string clean = cleanPath( args[2] );
	string tail = pathTail( clean, head );
	Id pa = shell_->doFind( head ).id;
	assert( pa != Id() );

	double nInit = atof( args[ poolMap_[ "nInit" ] ].c_str() );
	double vsf = atof( args[ poolMap_[ "vol" ] ].c_str() ); 
	/**
	 * vsf is vol scale factor, which is what GENESIS stores in 'vol' field
	 * n = vsf * conc( uM )
	 * Also, n = ( conc (uM) / 1e6 ) * NA * vol
	 * so, vol = 1e6 * vsf / NA
	 */
	double vol = 1.0e3 * vsf / KKIT_NA; // Converts volscale to actual vol in m^3
	int slaveEnable = atoi( args[ poolMap_[ "slave_enable" ] ].c_str() );
	double diffConst = atof( args[ poolMap_[ "DiffConst" ] ].c_str() );

	// I used -ve D as a flag to replace pool-specific D 
	// with the global value of D. Here we just ignore it.
	if ( diffConst < 0 ) 
		diffConst = 0;

	Id pool;
	if ( slaveEnable == 0 ) {
		pool = shell_->doCreate( "Pool", pa, tail, 1 );
	} else if ( slaveEnable & 4 ) {
		pool = shell_->doCreate( "BufPool", pa, tail, 1 );
	} else {
		pool = shell_->doCreate( "Pool", pa, tail, 1 );
		/*
		cout << "ReadKkit::buildPool: Unknown slave_enable flag '" << 
			slaveEnable << "' on " << clean << "\n";
			*/
		poolFlags_[pool] = slaveEnable;
	}
	assert( pool != Id() );
	// skip the 10 chars of "/kinetics/"
	poolIds_[ clean.substr( 10 ) ] = pool; 

	Field< double >::set( pool, "nInit", nInit );
	Field< double >::set( pool, "diffConst", diffConst );
	// SetGet1< double >::set( pool, "setVolume", vol );
	separateVols( pool, vol );
	poolVols_[pool] = vol;

	Id info = buildInfo( pool, poolMap_, args );

	/*
	cout << setw( 20 ) << head << setw( 15 ) << tail << "	" << 
		setw( 12 ) << nInit << "	" << 
		vol << "	" << diffConst << "	" <<
		slaveEnable << endl;
		*/
	numPools_++;
	return pool;
}
Exemplo n.º 5
0
Id ReadKkit::buildPlot( const vector< string >& args )
{
	string head;
	string tail = pathTail( cleanPath( args[2] ), head ); // Name of plot
	string temp;
	string graph = pathTail( head, temp ); // Name of graph

	Id pa = shell_->doFind( head ).id;
	assert( pa != Id() );

	Id plot = shell_->doCreate( "Table", pa, tail, 1 );
	assert( plot != Id() );

	temp = graph + "/" + tail;
	plotIds_[ temp ] = plot; 

	numPlot_++;
	return plot;
}
Exemplo n.º 6
0
Id ReadKkit::buildGraph( const vector< string >& args )
{
	string head;
	string tail = pathTail( cleanPath( args[2] ), head );

	Id pa = shell_->doFind( head ).id;
	assert( pa != Id() );
	Id graph = shell_->doCreate( "Neutral", pa, tail, 1 );
	assert( graph != Id() );
	numOthers_++;
	return graph;
}
Exemplo n.º 7
0
Id ReadKkit::buildGroup( const vector< string >& args )
{
	string head;
	string tail = pathTail( cleanPath( args[2] ), head );

	Id pa = shell_->doFind( head ).id;
	assert( pa != Id() );
	Id group = shell_->doCreate( "Neutral", pa, tail, 1 );
	assert( group != Id() );
	Id info = buildInfo( group, groupMap_, args );

	numOthers_++;
	return group;
}
Exemplo n.º 8
0
/**
 * Build a Kchan entry in simulation. For now a dummy Neutral.
 */
Id ReadKkit::buildChan( const vector< string >& args )
{
	string head;
	string clean = cleanPath( args[2] );
	string tail = pathTail( clean, head );
	Id pa = shell_->doFind( head ).id;
	assert( pa != Id() );

	cout << "Warning: Kchan not yet supported in MOOSE, creating dummy:\n"
		<< "	" << clean << "\n";
	Id chan = shell_->doCreate( "Neutral", pa, tail, 1 );
	assert( chan != Id() );
	string chanPath = clean.substr( 10 );
	chanIds_[ chanPath ] = chan;
	return chan;
}
Exemplo n.º 9
0
/**
 * Finds the source pool for a SumTot. It also deals with cases where 
 * the source is an enz-substrate complex
 */
Id ReadKkit::findSumTotSrc( const string& src )
{
	map< string, Id >::iterator i = poolIds_.find( src );
	if ( i != poolIds_.end() ) { 
		return i->second;
	}
	i = enzIds_.find( src );
	if ( i != enzIds_.end() ) {
		string head;
		string cplx = src + '/' + pathTail( src, head ) + "_cplx";
		i = poolIds_.find( cplx );
		if ( i != poolIds_.end() ) { 
			return i->second;
		}
	}
	cout << "Error: ReadKkit::findSumTotSrc: Cannot find source pool '" << src << endl;
	assert( 0 );
	return Id();
}
Exemplo n.º 10
0
//---------------------------------------------------------------------------
//  determineInstallFiles
//---------------------------------------------------------------------------
int CConfigGenEngine::determineInstallFiles(IPropertyTree& processNode, CInstallFiles& installFiles) const
{
    try
    {
        m_pCallback->printStatus(STATUS_NORMAL, NULL, NULL, NULL, 
            "Determining files to install for %s", processNode.queryProp("@name"));

        StringBuffer compListPath(CONFIGGEN_COMP_LIST);
        if (m_inDir.length())
            compListPath.clear().append(m_inDir).append(PATHSEPCHAR).append(CONFIGGEN_COMP_LIST);

        Owned<IPropertyTree> deployNode = createPTreeFromXMLFile(compListPath.str(), ipt_caseInsensitive);
        StringBuffer srcFilePath;
        srcFilePath.ensureCapacity(_MAX_PATH);
        const bool bFindStartable = &m_process == &processNode && m_startable == unknown;
        const bool bFindStoppable = &m_process == &processNode && m_stoppable == unknown;

        StringBuffer xpath;
        xpath.appendf("Component[@name=\"%s\"]",processNode.queryProp("@buildSet"));
        IPropertyTree* pComponent = deployNode->queryPropTree(xpath.str());

        if (!pComponent)
        {
            m_pCallback->printStatus(STATUS_NORMAL, NULL, NULL, NULL, 
                "Cannot find files to install for %s", processNode.queryProp("@buildSet"));
            return 0;
        }

        Owned<IPropertyTreeIterator> iter = pComponent->getElements("File");
        ForEach(*iter)
        {
            IPropertyTree* pFile = &iter->query();
            const char* name = pFile->queryProp("@name");

            if (!stricmp(name, "deploy_map.xml"))
                continue;

            if (bFindStartable && !strnicmp(name, "startup", sizeof("startup")-1))
                m_startable = yes;

            if (bFindStoppable && !strnicmp(name, "stop", sizeof("stop")-1))
                m_stoppable = yes;

            const char* method  = pFile->queryProp("@method");
            if (method && !stricmp(method, "schema"))
                continue;

            //if we are not deploying build files and method is copy then ignore this file
            if (!(m_deployFlags & DEFLAGS_BUILDFILES) && (!method || !stricmp(method, "copy")))
                continue;

            const char* srcPath = pFile->queryProp("@srcPath");
            const char* destPath= pFile->queryProp("@destPath");
            const char* destName= pFile->queryProp("@destName");
            bool bCacheable     = pFile->getPropBool("@cache", false);

            // Get source filespec
            if (srcPath && !strcmp(srcPath, "@temp"))
            {
                char tempfile[_MAX_PATH];
                getTempPath(tempfile, sizeof(tempfile), m_name);
                srcFilePath.clear().append(tempfile).append(name);
            }
            else
            {
                srcFilePath.clear().append(m_inDir);

        //adjust source paths
                if (srcPath && 0!=strcmp(srcPath, "."))
                {
                    if (!strncmp(srcPath, "..", 2) && (*(srcPath+2)=='/' || *(srcPath+2)=='\\'))
                    {
                        StringBuffer reldir(srcPath);
                        reldir.replace('/', '\\');

                        while (!strncmp(reldir.str(), "..\\", 3))
                        {
                            srcFilePath.setLength( srcFilePath.length() - 1 ); //remove last char PATHSEPCHAR
                            const char* tail = pathTail(srcFilePath.str());
                            srcFilePath.setLength( tail - srcFilePath.str() );
                            reldir.remove(0, 3);
                        }
                        srcFilePath.append(reldir).append(PATHSEPCHAR);
                    }
                    else
                        srcFilePath.append(srcPath).append(PATHSEPCHAR);
                }
                srcFilePath.append(name);
            }

            std::string sDestName;
            if (method && (!stricmp(method, "esp_service_module") || !stricmp(method, "esp_plugin")))
            {
                //if this is xsl transformation and we are not generating config files then ignore
                //
                if (!(m_deployFlags & DEFLAGS_CONFIGFILES) && !stricmp(method, "esp_service_module"))
                    continue;

                //if this file is an esp service module, encode name of service in the dest file name
                //so the esp deployment can figure out which service this file belongs to
                //
                const char* serviceName = processNode.queryProp("@name");

                //if destination name is specified then use it otherwise use <service-name>[index of module].xml
                sDestName = serviceName;
                if (destName)
                {
                    sDestName += '_';
                    sDestName += destName;
                }
                else
                {
                    int espServiceModules = m_envDepEngine.incrementEspModuleCount();
                    if (espServiceModules > 1)
                    {
                        char achNum[16];
                        itoa(espServiceModules, achNum, 10);

                        sDestName += achNum;
                    }
                    sDestName += ".xml";
                }
                //encode name of service herein - this is needed by and removed by CEspDeploymentEngine::processServiceModules()
                sDestName += '+';
                sDestName += processNode.queryProp("@name");//encode the name of service
            }
            else if (method && (!stricmp(method, "xsl") || !stricmp(method, "xslt")) && !(m_deployFlags & DEFLAGS_CONFIGFILES))
                continue;//ignore xsl transformations if we are not generating config files
            else
            {
                if (!method || !*method)
                    method = "copy";

                // Get destination filespec
                if (destName && *destName)
                {
                    //we now support attribute names within the destination file names like delimted by @ and + (optional)
                    //for e.g. segment_@attrib1+_file_@attrib2 would produce segment_attribval1_file_attrib2value
                    //+ not necessary if the attribute name ends with the word, for e.g. file_@attrib1
                    //for instnace, suite_@eclServer+.bat would expand to suite_myeclserver.bat
                    //if this process has an @eclServer with value "myeclserver"
                    //
                    if (strchr(destName, '@') || strchr(destName, '+'))
                    {
                        char* pszParts = strdup(destName);

                        char *saveptr;
                        const char* pszPart = strtok_r(pszParts, "+", &saveptr);
                        while (pszPart)
                        {
                            const char* p = pszPart;
                            if (*p)
                            {
                                if (strchr(p, '@'))//xpath for an attribute?
                                {
                                    // find name of attribute and replace it with its value
                                    const char* value = m_process.queryProp( p );
                                    if (value)
                                        sDestName.append(value);
                                }
                                else
                                    sDestName.append(p); //no attribute so copy verbatim
                            }
                            pszPart = strtok_r(NULL, "+", &saveptr);
                        }
                        free(pszParts);
                    }
                    else
                        sDestName = destName;


                    if (sDestName.empty())
                        throw MakeStringException(-1, "The destination file name '%s' for source file '%s' "
                        "translates to an empty string!", destName, name);
                }
            }

            StringBuffer destFilePath;
            destFilePath.ensureCapacity(_MAX_PATH);

            bool bTempFile = (destPath && !stricmp(destPath, "@temp")) ||
                !strnicmp(name, "@temp", 5); //@name starts with @temp or @tmp
            if (bTempFile)
            {
                if (sDestName.empty())//dest name not specified
                {
                    if (!strcmp(method, "copy"))
                        sDestName = name;
                    else
                    {
                        StringBuffer dir;
                        const char* pszFileName = splitDirTail(name, dir);
                        const char* pExt = findFileExtension(pszFileName);

                        if (pExt)
                            sDestName.append(pszFileName, pExt-pszFileName);
                        else
                            sDestName.append(pszFileName);

                        char index[16];
                        itoa(m_envDepEngine.incrementTempFileCount(), index, 10);
                        sDestName.append(index);

                        if (pExt)
                            sDestName.append(pExt);
                    }
                }
                destFilePath.append("@temp" PATHSEPSTR);
            }
            else
            {
                if (destPath && *destPath)
                {
                    destFilePath.append(destPath);
                    if (destPath[strlen(destPath)-1] != PATHSEPCHAR)
                        destFilePath.append(PATHSEPCHAR);
                }

                if (sDestName.empty())
                    sDestName = name;
            }

            if (!bTempFile)
                destFilePath.append(processNode.queryProp("@name")).append(PATHSEPCHAR);

            destFilePath.append(sDestName.c_str());

            //For oss, plugins to be handled globally, per Richard.
            //esp plugins also end with plugins.xml but they should be handled above.
            String destFilePathStr(destFilePath);
            String* tmpstr = destFilePathStr.toLowerCase();
            if (tmpstr->indexOf("plugins.xml") > 0)
            {
                delete tmpstr;
                createFakePlugins(destFilePath);
                continue;
            }

            delete tmpstr;

            //find all occurrences of this destination file in the map and resove any conflicts
            //like size mismatch etc.
            bool bAddToFileMap = installFiles.resolveConflicts(processNode, method, srcFilePath.str(), destFilePath.str(),
                m_name, m_curInstance, NULL);
            //resolve conflicts if method is not schema or exec
            if (0 != stricmp(method, "schema") && 0 != stricmp(method, "exec") && 0 != strnicmp(method, "del", 3)) 
            {
            }
            else if (!strnicmp(method, "del", 3))//treat files to be deleted as temp files - to be deleted AFTER we are done!
            {
                bTempFile = true;
                bAddToFileMap = false;
                m_envDepEngine.addTempFile(destFilePath.str());
            }


            if (bAddToFileMap)
            {
                if (bTempFile)
                    m_envDepEngine.addTempFile(destFilePath.str());

                //enable caching for files to be copied unless expressly asked not to do so
                //
                if (!bCacheable && !strcmp(method, "copy"))
                    bCacheable = pFile->getPropBool("@cache", true);

                installFiles.addInstallFile(method, srcFilePath.str(), destFilePath.str(), bCacheable, NULL);
            }
        }
    }
    catch (IException* e)
    {
        StringBuffer msg;
        e->errorMessage(msg);
        e->Release();
        throw MakeStringException(0, "Error creating file list for process %s: %s", m_name.get(), msg.str());
    }
    catch (...)
    {
        throw MakeErrnoException("Error creating file list for process %s", m_name.get());
    }

    m_pCallback->printStatus(STATUS_NORMAL, NULL, NULL, NULL, NULL);
    return installFiles.getInstallFileList().size();
}
Exemplo n.º 11
0
//------------------------------------------------------------------------------
//
MString CacheRepresentation::Factory::creationName(
   MPxAssembly* /* assembly */, const MString& input
) const
{
   return pathTail(input);
}
Exemplo n.º 12
0
void copyCompress(const char *from, const char *to, size32_t rowsize, bool fast, bool flzstrm, bool stats)
{
    Owned<IFile> srcfile = createIFile(from);
    Owned<IFileIO> baseio = srcfile->open(IFOread);
    if (!baseio) {
        printf("ERROR: could not open '%s' for read\n",from);
        doexit(3);
    }
    Owned<ICompressedFileIO> cmpio = createCompressedFileReader(baseio);
    Owned<IFileIOStream>  flzstrmsrc = cmpio?NULL:createFastLZStreamRead(baseio);
    bool plaincopy = false;
    IFileIO *srcio = NULL;
    if (cmpio) {
        srcio = cmpio;
        if (rowsize&&(cmpio->recordSize()==rowsize))
            plaincopy = true;
        else if (!rowsize) {
            if (fast&&(cmpio->method()==COMPRESS_METHOD_FASTLZ))
                plaincopy = true;
            else if (!fast&&(cmpio->method()==COMPRESS_METHOD_LZW))
                plaincopy = true;
        }
    }
    else if (flzstrmsrc) {
        if (flzstrm)
            plaincopy = true;
    }
    else
        srcio = baseio; 
    if (plaincopy) {
        cmpio.clear();
        srcio = baseio.get(); 
    }
    Owned<IFile> dstfile = createIFile(to);
    StringBuffer fulldst;
    if (dstfile->isDirectory()==foundYes) {
        dstfile.clear();
        addPathSepChar(fulldst.append(to)).append(pathTail(from));
        to = fulldst.str();
        dstfile.setown(createIFile(to));
    }

    if (dstfile->exists()) {
        printf("ERROR: file '%s' already exists\n",to);
        doexit(4);
    }
    unsigned start;
    unsigned startu;
    if (stats) {
         start = msTick();
         startu = usTick();
    }
    Owned<IFileIO> dstio;
    Owned<IFileIOStream>  flzstrmdst;
    if (plaincopy||flzstrm) {
        dstio.setown(dstfile->open(IFOcreate));
        if (dstio&&!plaincopy)
            flzstrmdst.setown(createFastLZStreamWrite(dstio));
    }
    else 
        dstio.setown(createCompressedFileWriter(dstfile,rowsize,false,true,NULL,fast));

    if (!dstio) {
        printf("ERROR: could not open '%s' for write\n",to);
        doexit(5);
    }
#ifdef __linux__
    // this is not really needed in windows - if it is we will have to
    // test the file extension - .exe, .bat

    struct stat info;
    if (stat(from, &info) == 0)  // cannot fail - exception would have been thrown above
        dstfile->setCreateFlags(info.st_mode&(S_IRUSR|S_IRGRP|S_IROTH|S_IWUSR|S_IWGRP|S_IWOTH|S_IXUSR|S_IXGRP|S_IXOTH));
#endif
    MemoryAttr mb;
    void * buffer = mb.allocate(BUFFERSIZE);

    offset_t offset = 0;
    try
    {
        loop {
            size32_t got = cmpio.get()?cmpio->read(offset, BUFFERSIZE, buffer):srcio->read(offset, BUFFERSIZE, buffer);
            if (got == 0)
                break;
            if (flzstrmdst)
                flzstrmdst->write(got,buffer);
            else
                dstio->write(offset, got, buffer);
            offset += got;
        }
    }
    catch (IException *e)
    {
        // try to delete partial copy
        dstio.clear();
        try {
            dstfile->remove();
        }
        catch (IException *e2) {
            StringBuffer s;
            pexception(s.clear().append("Removing partial copy file: ").append(to).str(),e2);
            e2->Release();
        }
        throw e;
    }
    flzstrmdst.clear();
    dstio.clear();
    if (stats) 
        printStats(offset,start,startu);
    CDateTime createTime, modifiedTime;
    if (srcfile->getTime(&createTime, &modifiedTime, NULL))
        dstfile->setTime(&createTime, &modifiedTime, NULL);
    printf("copied %s to %s%s\n",from,to,plaincopy?"":" compressing");
    { // print details 
        dstio.setown(dstfile->open(IFOread));
        if (dstio) {
            Owned<ICompressedFileIO> cmpio = createCompressedFileReader(dstio);
            Owned<IFileIOStream>  flzstrm = cmpio?NULL:createFastLZStreamRead(dstio);
            if (cmpio||flzstrm) 
                printCompDetails(to,dstio,cmpio,flzstrm);
            else 
                printf("destination %s not compressed\n",to);
        }
        else
            printf("destination %s could not be read\n",to);
    }
}
Exemplo n.º 13
0
Id ReadKkit::buildEnz( const vector< string >& args )
{
	string head;
	string clean = cleanPath( args[2] );
	string tail = pathTail( clean, head );
	Id pa = shell_->doFind( head ).id;
	assert ( pa != Id() );

	double k1 = atof( args[ enzMap_[ "k1" ] ].c_str() );
	double k2 = atof( args[ enzMap_[ "k2" ] ].c_str() );
	double k3 = atof( args[ enzMap_[ "k3" ] ].c_str() );
	// double volscale = atof( args[ enzMap_[ "vol" ] ].c_str() );
	double nComplexInit = 
		atof( args[ enzMap_[ "nComplexInit" ] ].c_str() );
	// double vol = atof( args[ enzMap_[ "vol" ] ].c_str());
	bool isMM = atoi( args[ enzMap_[ "usecomplex" ] ].c_str());
	assert( poolVols_.find( pa ) != poolVols_.end() );
	// double vol = poolVols_[ pa ];
	
	/**
	 * vsf is vol scale factor, which is what GENESIS stores in 'vol' field
	 * n = vsf * conc( uM )
	 * Also, n = ( conc (uM) / 1e6 ) * NA * vol
	 * so, vol = 1e6 * vsf / NA
	 */

	if ( isMM ) {
		Id enz = shell_->doCreate( "MMenz", pa, tail, 1 );
		assert( enz != Id () );
		string mmEnzPath = clean.substr( 10 );
		mmEnzIds_[ mmEnzPath ] = enz; 

		assert( k1 > EPSILON );
		double Km = ( k2 + k3 ) / k1;

		Field< double >::set( enz, "Km", Km );
		Field< double >::set( enz, "kcat", k3 );
		Id info = buildInfo( enz, enzMap_, args );
		numMMenz_++;
		return enz;
	} else {
		Id enz = shell_->doCreate( "Enz", pa, tail, 1 );
		// double parentVol = Field< double >::get( pa, "volume" );
		assert( enz != Id () );
		string enzPath = clean.substr( 10 );
		enzIds_[ enzPath ] = enz; 

		// Need to figure out what to do about these. Perhaps it is OK
		// to do this assignments in raw #/cell units.
		Field< double >::set( enz, "k3", k3 );
		Field< double >::set( enz, "k2", k2 );
		Field< double >::set( enz, "k1", k1 );

		string cplxName = tail + "_cplx";
		string cplxPath = enzPath + "/" + cplxName;
		Id cplx = shell_->doCreate( "Pool", enz, cplxName, 1 );
		assert( cplx != Id () );
		poolIds_[ cplxPath ] = cplx; 
		// Field< double >::set( cplx, "nInit", nComplexInit );
		Field< double >::set( cplx, "nInit", nComplexInit );

		// Use this later to assign mesh entries to enz cplx.
		enzCplxMols_.push_back( pair< Id, Id >(  pa, cplx ) );
		separateVols( cplx, -1 ); // -1 vol is a flag to defer mesh assignment for the cplx pool.

		ObjId ret = shell_->doAddMsg( "OneToAll", 
			ObjId( enz, 0 ), "cplx",
			ObjId( cplx, 0 ), "reac" ); 
		assert( ret != ObjId() );

		// cplx()->showFields();
		// enz()->showFields();
		// pa()->showFields();
		Id info = buildInfo( enz, enzMap_, args );
		numEnz_++;
		return enz;
	}
}
Exemplo n.º 14
0
static bool physicalPartCopy(IFile *from,const char *tofile, Owned<IException> &exc, StringBuffer *tmpname)
{
    StringBuffer tmpnamestr;
    if (!tmpname)
        tmpname = &tmpnamestr;
    tmpname->append(tofile).append("__");
    size32_t l = tmpname->length();
    genUUID(*tmpname,true); // true for windows
    StringAttr uuid(tmpname->str()+l);
    tmpname->append(".tmp");
    RemoteFilename tmpfn;
    tmpfn.setRemotePath(tmpname->str());
    //unsigned lastpc;
#ifdef LOG_PART_COPY
    PROGLOG("start physicalPartCopy(%s,%s)",from->queryFilename(),tmpname->str());
#endif
    try {
        recursiveCreateDirectoryForFile(tmpname->str());
        while(!asyncCopyFileSection(
                uuid,
                from,
                tmpfn,
                (offset_t)-1, // creates file
                0,
                (offset_t)-1, // all file
                NULL,
                PHYSICAL_COPY_POLL_TIME)) {
            // Abort check TBD
        }
    }
    catch (IException *e) {
        EXCLOG(e,"SingleFileCopy: File copy error");
        if (exc)
            exc.setown(e);
        else
            e->Release();
    }
    Owned<IFile> f = createIFile(tmpfn);
    if (!exc.get()&&(tmpnamestr.length()!=0)) {
        try {
#ifdef LOG_PART_COPY
            PROGLOG("physicalPartCopy rename(%s,%s)",tmpname->str(),pathTail(tofile));
#endif
            f->rename(pathTail(tofile));
        }
        catch (IException *e) {
            EXCLOG(e,"SingleFileCopy: File rename error");
            if (exc)
                exc.setown(e);
            else
                e->Release();
        }
    }
    if (exc.get()) {
        try {
            f->remove();
        }
        catch (IException *e) {
            // ignore
            e->Release();
        }
    }
#ifdef LOG_PART_COPY
    PROGLOG("done physicalPartCopy %s",(exc.get()==NULL)?"OK":"Failed");
#endif
    return exc.get()==NULL;
}
Exemplo n.º 15
0
void ReadKkit::addmsg( const vector< string >& args)
{
	string src = cleanPath( args[1] ).substr( 10 );
	string dest = cleanPath( args[2] ).substr( 10 );
	
	if ( args[3] == "REAC" ) {
		if ( args[4] == "A" && args[5] == "B" ) {
			// Ignore kchans
			if ( chanIds_.find( src ) != chanIds_.end() )
				; // found a kchan, do nothing
			else
				innerAddMsg( src, reacIds_, "sub", dest, poolIds_, "reac");
		} 
		else if ( args[4] == "B" && args[5] == "A" ) {
			// Ignore kchans
			if ( chanIds_.find( src ) != chanIds_.end() )
				; // found a kchan, do nothing
			else
				// dest pool is product of src reac
				innerAddMsg( src, reacIds_, "prd", dest, poolIds_, "reac");
		}
		else if ( args[4] == "sA" && args[5] == "B" ) {
			// Msg from enzyme to substrate.
			if ( mmEnzIds_.find( src ) == mmEnzIds_.end() )
				innerAddMsg( src, enzIds_, "sub", dest, poolIds_, "reac" );
			else
				innerAddMsg( src, mmEnzIds_, "sub", dest, poolIds_, "reac" );
		}
	}
	else if ( args[3] == "ENZYME" ) { // Msg from enz pool to enz site
		if ( mmEnzIds_.find( dest ) == mmEnzIds_.end() )
			innerAddMsg( dest, enzIds_, "enz", src, poolIds_, "reac" );
		else
			innerAddMsg( src, poolIds_, "nOut", dest, mmEnzIds_, "enzDest", 1);
			// innerAddMsg( dest, mmEnzIds_, "enz", src, poolIds_, "nOut", 1);
		/*
		if ( mmEnzIds_.find( dest ) == mmEnzIds_.end() )
			innerAddMsg( src, poolIds_, "reac", dest, enzIds_, "enz" );
		else
			innerAddMsg( src, poolIds_, "nOut", dest, mmEnzIds_, "enz" );
			*/
	}
	else if ( args[3] == "MM_PRD" ) { // Msg from enz to Prd pool
		if ( mmEnzIds_.find( src ) == mmEnzIds_.end() )
			innerAddMsg( src, enzIds_, "prd", dest, poolIds_, "reac" );
		else
			innerAddMsg( src, mmEnzIds_, "prd", dest, poolIds_, "reac" );
	}
	else if ( args[3] == "PLOT" ) { // Time-course output for pool
		string head;
		string temp;
		dest = pathTail( cleanPath( args[2] ), head );
		string graph = pathTail( head, temp );
		temp = graph + "/" + dest;
		map< string, Id >::const_iterator i = plotIds_.find( temp );
		assert( i != plotIds_.end() );
		Id plot = i->second;

		i = poolIds_.find( src );
		Id pool;
		if ( i == poolIds_.end() ) {
			i = enzIds_.find( src ); // might be plotting an enzCplx.
			if ( i == enzIds_.end() ) {
				cout << "Error: ReadKkit: Unable to find src for plot: " <<
					src << ", " << dest << endl;
				assert( 0 );
				return;
			}
			vector< Id > enzcplx;
			i->second.element()->getNeighbors( enzcplx, 
				i->second.element()->cinfo()->findFinfo( "toCplx" ) );
			assert( enzcplx.size() == 1 );
			pool = enzcplx[0];
		}  else {
			pool = i->second;
		}

		if ( args[4] == "Co" || args[4] == "CoComplex" ) {
			ObjId ret = shell_->doAddMsg( "Single",
				plot, "requestOut", pool, "getConc" );
			assert( ret != ObjId() );
		} else if ( args[4] == "n" || args[4] == "nComplex") {
			ObjId ret = shell_->doAddMsg( "Single",
				plot, "requestOut", pool, "getN" );
			assert( ret != ObjId() );
		} else {
			cout << "Unknown PLOT msg field '" << args[4] << "'\n";
		}
	}
	else if ( args[3] == "SUMTOTAL" ) { // Summation function.
		buildSumTotal( src, dest );
	}
	else if ( args[3] == "SLAVE" ) { // Summation function.
		if ( args[4] == "output" ) {
			setupSlaveMsg( src, dest );
		}
	}
}
Exemplo n.º 16
0
static void _doReplicate(CActivityBase *activity, IPartDescriptor &partDesc, ICopyFileProgress *iProgress)
{
    StringBuffer primaryName;
    getPartFilename(partDesc, 0, primaryName);;
    RemoteFilename rfn;
    IFileDescriptor &fileDesc = partDesc.queryOwner();
    unsigned copies = partDesc.numCopies();
    unsigned c=1;
    for (; c<copies; c++)
    {
        unsigned replicateCopy;
        unsigned clusterNum = partDesc.copyClusterNum(c, &replicateCopy);
        rfn.clear();
        partDesc.getFilename(c, rfn);
        StringBuffer dstName;
        rfn.getPath(dstName);
        assertex(dstName.length());

        if (replicateCopy>0 )  
        {
            try
            {
                queryThor().queryBackup().backup(dstName.str(), primaryName.str());
            }
            catch (IException *e)
            {
                Owned<IThorException> re = MakeActivityWarning(activity, e, "Failed to create replicate file '%s'", dstName.str());
                e->Release();
                activity->fireException(re);
            }
        }
        else // another primary
        {
            ActPrintLog(activity, "Copying to primary %s", dstName.str());
            StringBuffer tmpName(dstName.str());
            tmpName.append(".tmp");
            OwnedIFile tmpIFile = createIFile(tmpName.str());
            OwnedIFile srcFile = createIFile(primaryName.str());
            CFIPScope fipScope(tmpName.str());
            try
            {
                try
                {
                    ensureDirectoryForFile(dstName.str());
                    ::copyFile(tmpIFile, srcFile, 0x100000, iProgress);
                }
                catch (IException *e)
                {
                    IThorException *re = MakeActivityException(activity, e, "Failed to copy to tmp file '%s' from source file '%s'", tmpIFile->queryFilename(), srcFile->queryFilename());
                    e->Release();
                    throw re;
                }
                try
                {
                    OwnedIFile dstIFile = createIFile(dstName.str());
                    dstIFile->remove();
                    tmpIFile->rename(pathTail(dstName.str()));
                }
                catch (IException *e)
                {
                    IThorException *re = ThorWrapException(e, "Failed to rename '%s' to '%s'", tmpName.str(), dstName.str());
                    e->Release();
                    throw re;
                }
            }
            catch (IException *)
            {
                try { tmpIFile->remove(); }
                catch (IException *e) { ActPrintLog(&activity->queryContainer(), e, NULL); e->Release(); }
                throw;
            }
        }
    }
}
Exemplo n.º 17
0
int copyExpanded(const char *from, const char *to, bool stats)
{
    Owned<IFile> srcfile = createIFile(from);
    Owned<IFileIO> srcio = srcfile->open(IFOread);
    if (!srcio) {
        printf("ERROR: could not open '%s' for read\n",from);
        doexit(3);
    }
    Owned<ICompressedFileIO> cmpio = createCompressedFileReader(srcio);
    Owned<IFileIOStream>  flzstrm = cmpio?NULL:createFastLZStreamRead(srcio);
    int ret = 0;
    if (cmpio||flzstrm) 
        printCompDetails(from,srcio,cmpio,flzstrm);
    else {
        ret = 1;
        printf("%s is not compressed, size= %"I64F"d\n",from,srcio->size());
    }
    if (!to||!*to)
        return ret;
    Owned<IFile> dstfile = createIFile(to);
    StringBuffer fulldst;
    if (dstfile->isDirectory()==foundYes) {
        dstfile.clear();
        addPathSepChar(fulldst.append(to)).append(pathTail(from));
        to = fulldst.str();
        dstfile.setown(createIFile(to));
    }

    if (dstfile->exists()) {
        printf("ERROR: file '%s' already exists\n",to);
        doexit(4);
    }
    unsigned start;
    unsigned startu;
    if (stats) {
         start = msTick();
         startu = usTick();
    }
    Owned<IFileIO> dstio = dstfile->open(IFOcreate);
    if (!dstio) {
        printf("ERROR: could not open '%s' for write\n",to);
        doexit(5);
    }
#ifdef __linux__
    // this is not really needed in windows - if it is we will have to
    // test the file extension - .exe, .bat

    struct stat info;
    if (stat(from, &info) == 0)  // cannot fail - exception would have been thrown above
        dstfile->setCreateFlags(info.st_mode&(S_IRUSR|S_IRGRP|S_IROTH|S_IWUSR|S_IWGRP|S_IWOTH|S_IXUSR|S_IXGRP|S_IXOTH));
#endif
    MemoryAttr mb;
    void * buffer = mb.allocate(BUFFERSIZE);

    offset_t offset = 0;
    try
    {
        loop {
            size32_t got = cmpio.get()?cmpio->read(offset,BUFFERSIZE, buffer):
                (flzstrm?flzstrm->read(BUFFERSIZE, buffer):
                    srcio->read(offset, BUFFERSIZE, buffer));
            if (got == 0)
                break;
            dstio->write(offset, got, buffer);
            offset += got;
        }
    }
    catch (IException *e)
    {
        // try to delete partial copy
        dstio.clear();
        try {
            dstfile->remove();
        }
        catch (IException *e2) {
            StringBuffer s;
            pexception(s.clear().append("Removing partial copy file: ").append(to).str(),e2);
            e2->Release();
        }
        throw e;
    }
    dstio.clear();
    if (stats) 
        printStats(offset,start,startu);
    CDateTime createTime, modifiedTime;
    if (srcfile->getTime(&createTime, &modifiedTime, NULL))
        dstfile->setTime(&createTime, &modifiedTime, NULL);
    printf("copied %s to %s%s\n",from,to,cmpio.get()?" expanding":"");
    return 0;
}