Beispiel #1
0
System* MolecularFileDialog::openFile_(String type)
{
	QStringList files = QFileDialog::getOpenFileNames(
											0,
											tr("Choose a molecular file to open"),
											getWorkingDir().c_str(),
											"*.*");

	System* system = 0;
	for (QStringList::Iterator it = files.begin(); it != files.end(); ++it) 
	{
		vector<String> fields;
		String seperators(FileSystem::PATH_SEPARATOR);
		// workaround on windows: QT returns the filename in linux style
		// but I am not sure, if this will stay this way.
#ifdef BALL_OS_WINDOWS
		 seperators += "/";
#endif
		String file = ascii(*it);
		Position p = file.split(fields, seperators.c_str()) -1;
		String filename = fields[p];				
		setWorkingDirFromFilename_(file);

		// construct a name for the system(the filename without the dir path)
		system = openMolecularFile(file, type, filename);
	}

	return system;
}
Beispiel #2
0
void TestFramework::loadFile()
{
	QString file = QFileDialog::getOpenFileName(0,
										"Choose a test file",
										getWorkingDir().c_str(),
										"*.btf");

	if (ascii(file) == "") return;

	filename_ = ascii(file);
	setWorkingDirFromFilename_(filename_);
}
Beispiel #3
0
System* MolecularFileDialog::openMolecularFile(const String& file)
{
	vector<String> fields;
	String seperators(FileSystem::PATH_SEPARATOR);
	// workaround on windows: QT returns the filename in linux style
	// but I am not sure, if this will stay this way.
#ifdef BALL_OS_WINDOWS
	 seperators += "/";
#endif
	Position p = file.split(fields, seperators.c_str()) -1;
	String filename = fields[p];				
	setWorkingDirFromFilename_(file);
	String extension = fields[filename.split(fields, ".") -1];
	filename = filename.getSubstring(0, filename.size() - (extension.size() + 1));
	return openMolecularFile(file, extension, filename);
}
Beispiel #4
0
bool MolecularFileDialog::writeFile()
{
	list<Composite*>& selection = getMainControl()->getMolecularControlSelection();

    if (selection.size() != 1 || !RTTI::isKindOf<System> (*selection.begin()))
	{
		setStatusbarText((String)tr("Not a single system selected! Aborting writing..."), true);
		return false;
	}

	const System& system = *(const System*) (*selection.begin());
	String file_name = getWorkingDir();
	file_name += FileSystem::PATH_SEPARATOR;
	file_name += system.getName();
	file_name += ".pdb";

	QString s = QFileDialog::getSaveFileName(
								0,
								tr("Choose a filename to save the selected system"),
								file_name.c_str(),
								getSupportedFileFormats().c_str());

	if (s == QString::null) return false;

	setStatusbarText((String)tr("writing file..."));

	String filename = ascii(s);
	setWorkingDirFromFilename_(filename);

	String filter(filename);
	while (filter.has(FileSystem::PATH_SEPARATOR))
	{
		filter = filter.after(FileSystem::PATH_SEPARATOR);
	}

	String filename_without_path = filter;

	while (filter.has('.'))
	{
		filter = filter.after(".");
	}

	bool result = false;
	if (filter == "PDB" || filter == "pdb" ||
			filter == "ent" || filter == "ENT" ||
			filter == "brk" || filter == "BRK")
	{
		result = writePDBFile(filename, system);
	}
	else if (filter.hasSubstring("HIN") || filter.hasSubstring("hin"))
	{
		result = writeHINFile(filename, system);
	}
	else if (filter.hasSubstring("MOL2") || filter.hasSubstring("mol2"))
	{
		result = writeMOL2File(filename, system);
	}
	else if (filter.hasSubstring("MOL") || filter.hasSubstring("mol"))
	{
		result = writeMOLFile(filename, system);
	}
	else if (filter.hasSubstring("SDF") || filter.hasSubstring("sdf"))
	{
		result = writeSDFile(filename, system);
	}	
	else if (filter.hasSubstring("AC") || filter.hasSubstring("ac"))
	{
		result = writeACFile(filename, system);
	}
	else if (filter.hasSubstring("XYZ") || filter.hasSubstring("xyz"))
	{
		result = writeXYZFile(filename, system);
	}
	else
	{
		if (filter == filename_without_path)
		{
			filename += ".pdb";
			result = writePDBFile(filename, system);
		}
		else
		{
			setStatusbarText((String)tr("Unknown file format, please set the file extension accordingly to type, aborting..."), true);
			return false;
		}
	}

	if (!result) 
	{
		return false;
	}

	setStatusbarText(String(system.countAtoms()) + " " + (String)tr("atoms written to file") + " \"" + filename + "\"", true);
	return true;
}