Esempio n. 1
0
                        HLoggerPtr LoggerUtil::getLogger(const char* id) {
#ifdef HAVE_LOG4CXX
                            return LoggerPtr(Logger::getLogger(id));
#else
                            return (HLoggerPtr)id;
#endif
                        }
Esempio n. 2
0
int main( int argc, char ** argv )
{
    //create qt application
    Application a( argc,( char **) argv );
    loadLocalizations( a, "src/lintouch-runtime/locale", "runtime_" );

    a.connect( &a, SIGNAL( lastWindowClosed() ), SLOT( quit() ) );

    printBanner( argv[0] );

    if( lt_ui_initialize() == -1 ) {
        qWarning( "Unable to initialize Lintouch Panel Library" );
        return -1;
    }
    atexit( lt_ui_terminate );

    if( lt_cp_initialize() == -1 ) {
        qWarning( "Unable to initialize "
                  "Lintouch Communication Protocol Library" );
        return -1;
    }
    atexit( lt_cp_terminate );

    //parse commandline args and remember them so they can be later passed
    // 0 - false, 1 - true, 2 - unspecified = project dependent
    // host/port/project related
    bool startServer = 1;
    QString host_or_project;
    int hostPortSelection = 2;
    int projectSelection = 2;
    // view/panel selection related
    int viewSelection = 2;
    int panelSelection = 2;
    bool servicePanelShortcut = true;
    // windows size related
    bool fullscreen = true;
    bool showFullScreenShortcut = true;
    // view related
    QString view;
    // port related
    int port = 5555;
    bool portGiven = false;
    // debug
    QString debug_fn;   // empty means no-debug

    for( int i = 1; i < argc; i ++ ) {
        if( ( QString( "-h" ) == argv[ i ] ) ||
                ( QString( "--help" ) == argv[ i ] ) ) {
            printUsage( argv[0] );
            exit( 1 );
        }

        if( ( QString( "-p" ) == argv[ i ] ) ||
                ( QString( "--port" ) == argv[ i ] ) ) {
            if ( ++i >= argc ) {
                qWarning ( "ERROR: No port specified" );
                printUsage( argv[ 0 ] );
                exit( 1 );
            }
            port = atoi( argv[ i ] );
            portGiven = true;
            continue;
        }

        if( ( QString( "-v" ) == argv[ i ] ) ||
                ( QString( "--view" ) == argv[ i ] ) ) {
            if ( ++i >= argc ) {
                qWarning ( "ERROR: No view specified" );
                printUsage( argv[ 0 ] );
                exit( 1 );
            }
            view = argv[ i ];
            continue;
        }

        if( ( QString( "-f" ) == argv[ i ] ) ||
                ( QString( "--fullscreen" ) == argv[ i ] ) ) {
            fullscreen = true;
            continue;
        }

        if( ( QString( "-n" ) == argv[ i ] ) ||
                ( QString( "--normal" ) == argv[ i ] ) ) {
            fullscreen = false;
            continue;
        }

        if( QString( "--debug" ) == argv[ i ] ) {
            if ( ++i >= argc ) {
                qWarning ( "ERROR: No filename specified" );
                printUsage( argv[ 0 ] );
                exit( 1 );
            }
            debug_fn = argv[ i ];
            continue;
        }

        if( ( QString( "--enable-host-port-selection" ) == argv[ i ] ) ) {
            hostPortSelection = 1;
            continue;
        }
        if( ( QString( "--disable-host-port-selection" ) == argv[ i ] ) ) {
            hostPortSelection = 0;
            continue;
        }
        if( ( QString( "--enable-project-selection" ) == argv[ i ] ) ) {
            projectSelection = 1;
            continue;
        }
        if( ( QString( "--disable-project-selection" ) == argv[ i ] ) ) {
            projectSelection = 0;
            continue;
        }
        if( ( QString( "--enable-view-switching" ) == argv[ i ] ) ) {
            viewSelection = 1;
            continue;
        }
        if( ( QString( "--disable-view-switching" ) == argv[ i ] ) ) {
            viewSelection = 0;
            continue;
        }
        if( ( QString( "--enable-panel-switching" ) == argv[ i ] ) ) {
            panelSelection = 1;
            continue;
        }
        if( ( QString( "--disable-panel-switching" ) == argv[ i ] ) ) {
            panelSelection = 0;
            continue;
        }
        if( ( QString( "--enable-service-panel-shortcut" ) == argv[ i ] ) ) {
            servicePanelShortcut = true;
            continue;
        }
        if( ( QString( "--disable-service-panel-shortcut" ) == argv[ i ] ) ) {
            servicePanelShortcut = false;
            continue;
        }
        if( ( QString( "--enable-fullscreen-shortcut" ) == argv[ i ] ) ) {
            showFullScreenShortcut = true;
            continue;
        }
        if( ( QString( "--disable-fullscreen-shortcut" ) == argv[ i ] ) ) {
            showFullScreenShortcut = false;
            continue;
        }

        if( QString( argv[ i ] ).startsWith( "-" ) ) {
            qWarning( "ERROR: Invalid argument specified: %s",
                    argv[ i ] );
            printUsage( argv[ 0 ] );
            exit( 1 );
        }

        host_or_project = argv[ i ];
    }

    // validate commandline args

    // problematic combinations
    if( hostPortSelection == 1 && projectSelection == 1 ) {
        qWarning( "ERROR: --enable-host-port-selection and "
                "--enable-project-selection"
                " can not be specified at the same time" );
        printUsage( argv[ 0 ] );
        exit( 1 );
    }
    if( hostPortSelection == 0 && projectSelection == 0 ) {
        qWarning( "ERROR: --disable-host-port-selection and "
                "--disable-project-selection"
                " can not be specified at the same time" );
        printUsage( argv[ 0 ] );
        exit( 1 );
    }

    // no special --enable given, try to determine mode according to given
    // host_or_project
    if( hostPortSelection == 2 && projectSelection == 2 ) {
        if( host_or_project.isEmpty() || QFile::exists( host_or_project ) ) {
            projectSelection = 1;
        } else {
            hostPortSelection = 1;
        }
    }

    // handle non-specified arguments and their defaults
    if( hostPortSelection == 0 ) {
        switch( projectSelection ) {
            case 1:
            case 2:
                startServer = true;
                projectSelection = 1;
                break;
        }
    } else if( hostPortSelection == 1 ) {
        switch( projectSelection ) {
            case 0:
            case 2:
                startServer = false;
                projectSelection = 0;
                break;
        }
    } else if( hostPortSelection == 2 ) {
        switch( projectSelection ) {
            case 0:
                startServer = false;
                hostPortSelection = 1;
                break;
            case 1:
            case 2:
                startServer = true;
                projectSelection = 1;
                hostPortSelection = 0;
                break;
        }
    }

    // when no port has been specified and we are supposed to start local
    // server, we'll use an unused port
    // generated for us by ServerController
    if( startServer && ! portGiven ) port = 0;

    // print summary
    if( !host_or_project.isEmpty() ) {
        if( startServer ) {
            host_or_project = QFileInfo( host_or_project ).absFilePath();
            qWarning( QString( "Starting server %1:%2 with project %3" )
                    .arg( "localhost" ).arg( port ).arg( host_or_project ) );
        } else {
            qWarning( QString( "Using server %1:%2" )
                    .arg( host_or_project ).arg( port ) );
        }
    }
    if( !view.isEmpty() ) {
        qWarning( QString( "Using view %1" ).arg( view ) );
    }

    LoggerPtr l;
    if( debug_fn.isEmpty() ) {
        l = LoggerPtr( new lt::Logger );
    } else {
        l = LoggerPtr( new lt::FileLogger(debug_fn, "",
                    lt::FileLogger::LEVEL_DEBUG) );
    }

    // create main window
    MainWindow mw( startServer, fullscreen, l, NULL );

    // pass in commmand line defaults
    if( startServer ) {
        mw.setProjectNPort( host_or_project, port, host_or_project.isEmpty() );
    } else {
        mw.setHostNPort( host_or_project, port, host_or_project.isEmpty() );
    }
    mw.setViewSelectorEnabled( viewSelection );
    mw.setPanelSelectorEnabled( panelSelection );
    mw.setView( view );
    mw.setServicePanelShortcutEnabled( servicePanelShortcut );
    mw.setShowFullScreenEnabled( showFullScreenShortcut );

    // and go ahead with startup
    a.setMainWidget( &mw );

    if( fullscreen ) {
        mw.showFullScreen();
    } else {
        mw.show();
    }

    return a.exec();
}
Esempio n. 3
0
void new_main(int argc, char *argv[])
{
    time_t startcputime;
    time(&startcputime);
    
	if (argc == 1)
	{
        std::cout << "Welcome to cppxfel version 1.1.1!" << std::endl;
        std::cout << "Please refer to & cite paper in Journal of Applied Crystallography (unpublished)" << std::endl << std::endl;
        std::cout << "Command order for regular structure solution:" << std::endl;
        std::cout << "\tcppxfel.run_dials shot*.pickle" << std::endl;
        std::cout << "\tcppxfel.input_gen" << std::endl;
        std::cout << "\tcppxfel.run -i integrate.txt" << std::endl;
        std::cout << "\tcppxfel.run -i refine.txt" << std::endl;
        std::cout << "\tcppxfel.run -i merge.txt" << std::endl << std::endl;;
        std::cout << "Other functions for assessing data quality:" << std::endl << std::endl;
        
        std::cout << "Correlation between two MTZ files:" << std::endl << std::endl;
        std::cout << "\tcppxfel.run -cc firstFile.mtz secondFile.mtz [ambiguity] [lowRes] [highRes] [bins]" << std::endl << std::endl;
        std::cout << "ambiguity: 0, 1, 2 or 3 - will compare different indexing solutions where the Bravais lattice symmetry is higher than that of the point group for certain space groups. Default 0" << std::endl;
        std::cout << "lowRes and highRes: set to resolution in Angstroms to bound the results, or set to 0 to take lowest/highest resolution data. Default 0, 0" << std::endl;
        std::cout << "bins: number of bins to report correlation statistics. Default 20." << std::endl << std::endl;
        
        std::cout << "Partiality CSV files:" << std::endl << std::endl;
        std::cout << "\tcppxfel.run -partiality reference.mtz ref-img-shot-number.mtz [highRes]" << std::endl << std::endl;
        std::cout << "highRes: 0, 1, 2 or 3 - highest resolution reflection to report results on. Default 1.4" << std::endl;
        std::cout << "This outputs partiality_[m].csv where m is bin number, which can be imported into other graphing softwares such as R." << std::endl << std::endl;;

        
        std::cout << "Merging statistics:" << std::endl << std::endl;
        std::cout << "\tcppxfel.run -rpim unmerged_file.mtz [lowRes] [highRes] [bins]" << std::endl;
        std::cout << "\tcppxfel.run -rmeas unmerged_file.mtz [lowRes] [highRes] [bins]" << std::endl;
        std::cout << "\tcppxfel.run -rmerge unmerged_file.mtz [lowRes] [highRes] [bins]" << std::endl << std::endl;
        std::cout << "lowRes and highRes: set to resolution in Angstroms to bound the results, or set to 0 to take lowest/highest resolution data. Default 0, 0" << std::endl;
        std::cout << "bins: number of bins to report correlation statistics. Default 20." << std::endl << std::endl;
        
        exit(1);
	}

	if (strcmp(argv[1], "-wiki") == 0)
	{
		if (argc <= 2)
		{
			std::cout << "arguments: -wiki <logfile>" << std::endl;
			exit(1);
		}

        Wiki wiki = Wiki(std::string(argv[2]));
		wiki.process();

		exit(1);
	}
    
	std::cout << "Welcome to cppxfel!" << std::endl;
    
	if (strcmp(argv[1], "-i") == 0 || strcmp(argv[1], "-dry") == 0)
	{
        bool dry = (strcmp(argv[1], "-dry") == 0);
        
		if (argc < 3)
		{
			std::cout << "arguments: -i <input_script>" << std::endl;
			exit(1);
		}

        std::vector<std::string> extras;
        
        for (int i = 3; i < argc; i++)
        {
            extras.push_back(std::string(argv[i]));
        }
        
        InputFileParser *parser = new InputFileParser(std::string(argv[2]), extras);
        parser->setDry(dry);
		parser->parse(false);
        
        delete parser;
	}
    else
    {
        Logger::mainLogger = LoggerPtr(new Logger());
        boost::thread thr = boost::thread(Logger::awaitPrintingWrapper, Logger::mainLogger);
    }
    
    if (strcmp(argv[1], "-b") == 0)
    {
        float bFactor = atof(argv[2]);
        
        MtzManager *mtz1 = new MtzManager();
        mtz1->setFilename(std::string(argv[3]));
        mtz1->loadReflections(0);
        
        mtz1->applyBFactor(bFactor);
        
        mtz1->writeToFile("b-" + std::string(argv[3]));

    }
    
	if (strcmp(argv[1], "-rmerge") == 0 || strcmp(argv[1], "-rpim") == 0
			|| strcmp(argv[1], "-rmeas") == 0)
	{
		if (argc < 3)
		{
			std::cout << "arguments: -r{merge} <file1> [lowRes] [highRes] [bins]."
					<< std::endl;
			exit(1);
		}

		RFactorType rFactor = RFactorTypeMerge;

		if (strcmp(argv[1], "-rpim") == 0)
		{
			rFactor = RFactorTypePim;
		}
		else if (strcmp(argv[1], "-rmeas") == 0)
		{
			rFactor = RFactorTypeMeas;
		}

		double highRes = 0;
		double lowRes = 0;
		int bins = 20;

		if (argc > 5)
		{
			lowRes = atof(argv[4]);
			highRes = atof(argv[5]);
		}
		if (argc > 6)
		{
			bins = atoi(argv[6]);
		}

        MtzManager *mtz = new MtzManager();
		mtz->setFilename(std::string(argv[2]));
		mtz->loadReflections(1);

		mtz->rFactorWithManager(rFactor, false, false, lowRes, highRes, bins);
	}

	if (strcmp(argv[1], "-cc") == 0 || strcmp(argv[1], "-rsplit") == 0)
	{
		if (argc < 4)
		{
			std::cout
					<< "arguments: -cc <file1> <file2> (0 / 1) [lowRes] [highRes] [bins]."
					<< std::endl;
			exit(1);
		}

		bool rsplit = (strcmp(argv[1], "-rsplit") == 0);

		int inverted = 0;
		double highRes = 0;
		double lowRes = 0;
		int bins = 20;

		if (argc > 4)
		{
			inverted = atoi(argv[4]);
		}
		if (argc > 6)
		{
			lowRes = atof(argv[5]);
			highRes = atof(argv[6]);
		}
		if (argc > 7)
		{
			bins = atoi(argv[7]);
		}

		MtzManager *mtz1 = new MtzManager();
		mtz1->setFilename(std::string(argv[2]));
		mtz1->loadReflections(1);

		MtzManager *mtz2 = new MtzManager();
		mtz2->setFilename(std::string(argv[3]));
		mtz2->loadReflections(PartialityModelScaled, true);

		if (inverted)
            mtz1->setActiveAmbiguity(1);

		if (rsplit)
		{
			mtz1->rSplitWithManager(mtz2, 1, 0, lowRes, highRes, bins);
		}
		else
		{
			mtz1->correlationWithManager(mtz2, 1, 0, lowRes, highRes, bins, NULL, true);

		}

		delete mtz1;
		delete mtz2;

		exit(1);
	}

	if (strcmp(argv[1], "-gradscaling") == 0)
	{
		if (argc <= 3)
		{
			std::cout << "arguments: -gradscaling <ref> <file2> ... <filen>."
					<< std::endl;
			exit(1);
		}

		MtzManager *reference = new MtzManager();
		reference->setFilename(argv[2]);
		reference->loadReflections(1);

		for (int i = 3; i < argc; i++)
		{
			MtzManager *image = new MtzManager();
			image->setFilename(argv[i]);
			image->loadReflections(1);

			double gradientOld = image->gradientAgainstManager(reference);
			double gradientBefore = image->minimizeRFactor(reference);

			std::cout << image->getFilename() << "\t" << gradientOld << "\t"
					<< gradientBefore << std::endl;
		}
	}

	if (strcmp(argv[1], "-inv") == 0)
	{
		if (argc <= 2)
		{
			std::cout << "arguments: -inv <file>." << std::endl;
			exit(1);
		}
        
        MtzManager *mtz = new MtzManager();
		mtz->setFilename(std::string(argv[2]));
		mtz->loadReflections(1);
        mtz->setActiveAmbiguity(1);

		mtz->writeToFile(std::string("inv-") + argv[2], false, false, true);
	}

	if (strcmp(argv[1], "-stats") == 0)
	{
		if (argc < 3)
		{
			std::cout << "arguments: -stats <filein> <threshold>." << std::endl;
			exit(1);
		}

		if (argc >= 3)
		{
			StatisticsManager stats;
			stats.loadFiles(&argv[2], 1, 0);
            
            double threshold = -100;
            int h = 0; int k = 0; int l = 0;
            
            if (argc >= 3)
            {
                threshold = atof(argv[3]);
                std::cout << "Threshold set to " << threshold << std::endl;
            }
            
            if (argc >= 6)
            {
                h = atoi(argv[4]);
                k = atoi(argv[5]);
                l = atoi(argv[6]);

                std::cout << "Searching for " << h << " " << k << " " << l << std::endl;
            }

            GraphDrawer drawer = GraphDrawer(&*stats.mtzs[0]);
            drawer.plotPartialityStats(h, k, l);
		}
	}
    
    if (strcmp(argv[1], "-intensities") == 0)
    {
        if (argc <= 5)
        {
            std::cout << "arguments: -intensities h k l <file1> {<file2> ...}." << std::endl;
            exit(1);
        }
        
        int h = atoi(argv[2]);
        int k = atoi(argv[3]);
        int l = atoi(argv[4]);
        
        if (h == 0 && k == 0 && l == 0)
        {
            h = (double)(rand() / RAND_MAX) * 40;
            k = (double)rand() / RAND_MAX * (40 - h) + h;
            l = (double)rand() / RAND_MAX * (40 - k) + k;
        }
        
        std::cout << "Plotting intensities for (" << h << ", " << k << ", " << l << ")" << std::endl;
        
        
        std::vector<MtzPtr> mtzs;
        
        for (int i = 5; i < argc; i++)
        {
            MtzPtr mtz = MtzPtr(new MtzManager());
            mtz->setFilename(argv[i]);
            mtz->loadReflections(1);
            
            mtzs.push_back(mtz);
        }
        
        GraphDrawer drawer = GraphDrawer(&*mtzs[0]);
        drawer.plotReflectionFromMtzs(mtzs, h, k, l);
    }

#ifdef MAC
    if (strcmp(argv[1], "-partiality") == 0)
	{
		if (argc <= 3)
		{
			std::cout << "arguments: -partiality <ref> <filein> {<maxres>}." << std::endl;
			exit(1);
		}

		MtzManager *reference = new MtzManager();
		reference->setFilename(argv[2]);
		reference->loadReflections(1);
		MtzManager::setReference(reference);
        
        double maxRes = 1.6;
        
        if (argc > 4)
        {
            maxRes = atof(argv[4]);
        }
        
        
        MtzManager *mtz = new MtzManager();
        mtz->setFilename(argv[3]);
        std::cout << "Partiality plot for " << argv[3] << std::endl;
        mtz->loadReflections(PartialityModelNone, true);
        
        vector<Reflection *>refReflections, imageReflections;
        
        GraphDrawer graph = GraphDrawer(mtz);
        
        graph.partialityPlot("partiality", GraphMap(), maxRes);
        
        delete mtz;

		delete reference;
	}
    
    if (strcmp(argv[1], "-scale") == 0)
    {
        if (argc <= 3)
        {
            std::cout << "arguments: -scale <ref> <file1>." << std::endl;
            exit(1);
        }
        
        MtzManager *reference = new MtzManager();
        reference->setFilename(argv[2]);
        reference->loadReflections(1);
        MtzManager::setReference(reference);
        
        MtzManager *mtz = new MtzManager();
        mtz->setFilename(argv[3]);
        mtz->loadReflections(1);
        
        mtz->applyScaleFactorsForBins(50);
        mtz->writeToFile("scaled-" + std::string(argv[3]));
    }
    
    if (strcmp(argv[1], "-bfac") == 0)
    {
        MtzManager *reference = new MtzManager();
        reference->setFilename(argv[2]);
        reference->loadReflections(1);
        
        double bFactor = atof(argv[3]);
        
        reference->applyBFactor(bFactor);
        reference->writeToFile("bfac-" + reference->getFilename(), true);
        
    }
    
	if (strcmp(argv[1], "-bfactor") == 0)
	{
		if (argc <= 2)
		{
			std::cout << "arguments: -bfactor <ref> <file1> {<file2> ...}." << std::endl;
			exit(1);
		}

		vector<MtzManager *> managers = vector<MtzManager *>();

		MtzManager *reference = new MtzManager();
		reference->setFilename(argv[2]);
		reference->loadReflections(1);
		MtzManager::setReference(reference);
        FileParser::setKey("REFINE_B_FACTOR", true);
        
		for (int i = 3; i < argc; i++)
		{
			MtzManager *mtz = new MtzManager();
			mtz->setFilename(argv[i]);
			mtz->loadReflections(1);
            managers.push_back(mtz);
		}

		GraphDrawer graph = GraphDrawer(reference);

		graph.resolutionStatsPlot(managers, "intensity_bins", GraphMap(), true,
				false);
		graph.resolutionStatsPlot(managers, "intensity_bins_2", GraphMap(),
				true, true);
		graph.resolutionStatsPlot(managers);
        graph.bFactorPlot(managers);
        
		for (int i = 0; i < managers.size(); i++)
			delete managers[i];

	}

	if (strcmp(argv[1], "-ccplot") == 0)
	{
		MtzManager *reference = new MtzManager();
		reference->setFilename(argv[2]);
		reference->loadReflections(1);
		MtzManager::setReference(reference);

		for (int i = 3; i < argc; i++)
		{
			MtzManager *image = new MtzManager();
			image->setFilename(argv[i]);
			image->loadReflections(1);

			GraphDrawer graph = GraphDrawer(image);
			graph.correlationPlot("correl");

			delete image;
		}

		delete reference;
	}
#endif
    
    time_t endcputime;
    time(&endcputime);
    
    clock_t difference = endcputime - startcputime;
    double seconds = difference;
    
    int finalSeconds = (int) seconds % 60;
    int minutes = seconds / 60;
    
    std::ostringstream logged;
    logged << "N: Total time: " << minutes << " minutes, "
    << finalSeconds << " seconds (" << seconds << " seconds)." << std::endl;

	logged << "Done" << std::endl;
    Logger::mainLogger->addStream(&logged);
    
    if (strcmp(argv[1], "-i") == 0)
        finishJobNotification(argc, argv, minutes);
    
    sleep(2);
}
Esempio n. 4
0
	LoggerPtr Logger::getLogger(const std::string& name)
	{
		return LoggerPtr(name);
	}