<commit_before>// -*- Mode: C++; tab-width: 2; -*-
// vi: set ts=2:
//

#include <BALL/FORMAT/PDBFile.h>
#include <BALL/FORMAT/commandlineParser.h>

#include <BALL/MATHS/angle.h>

#include <BALL/STRUCTURE/peptideBuilder.h>
#include <BALL/STRUCTURE/fragmentDB.h>
#include <BALL/STRUCTURE/peptides.h>

#include <vector>
#include <iostream>
#include "version.h"

using namespace std;
using namespace BALL;

void usage (const char *progname);

int main (int argc, char **argv)
{
	CommandlineParser parpars("PeptideBuilder", "build a peptide  ", VERSION, String(__DATE__), "Preparation");
	parpars.registerParameter("i", "input torsion-file", INFILE, true);
	parpars.registerParameter("o", "peptide output pdb-file", OUTFILE, true);
	//parpars.registerParameter("peptide_name", "name of the peptide", STRING, false);

	String man = "This tool creates a peptide by a given torsion file. The amino acids shall be given in three letter code, the phi, psi, and omega angles shall be given in degree.\nExample:\n# aa   phi    psi   omega\nA    -180    140\nC    -180    180\nG    -90    -140\nP    -65    -40       0   # cis\nT    -120    -90\nP    -78     146     180  # trans";

	parpars.setToolManual(man);
	parpars.setSupportedFormats("i", "txt");
	parpars.setSupportedFormats("o", "pdb");
	parpars.parse(argc, argv);

	// initialize the peptide builder
	BALL::Peptides::PeptideBuilder* pb = new BALL::Peptides::PeptideBuilder;

	// "link" the fragment db for adding missing information
  FragmentDB fdb("");
  pb->setFragmentDB(&fdb);

	// read the torsion file (format AA, PHI, PSI)
	// e.g. ALA 109 65
	LineBasedFile torsion_file(parpars.get("i"), std::ios::in);
	vector<String> fields;
	while (torsion_file.LineBasedFile::readLine())
	{
		// get the line
		String aa_torsion = torsion_file.getLine();

		if ((aa_torsion.countFields(" ")>0) && (aa_torsion(0,1) != "#"))
		{
			fields.clear();
			aa_torsion.split(fields);

			// split and check
			if (   (fields.size()<3)
					|| ((fields.size()>3) && (fields[3] != "#") && (fields[4] != "#") ))
			{
				Log.error() << "Error in while reading file " << parpars.get("i") << " in line " << aa_torsion << endl;
			}

			String aa = fields[0];
			float phi = fields[1].toFloat();
			float psi = fields[2].toFloat();
			float omega = 0.;

			if ((fields.size()>4) && (fields[3] != "#"))
				omega = fields[3].toFloat();

			char test_aa = aa.toChar();
<commit_msg>PeptideBuilderTool: allow peptide creation by AAA sequence<commit_after>// -*- Mode: C++; tab-width: 2; -*-
// vi: set ts=2:
//

#include <BALL/FORMAT/PDBFile.h>
#include <BALL/FORMAT/commandlineParser.h>

#include <BALL/MATHS/angle.h>

#include <BALL/STRUCTURE/peptideBuilder.h>
#include <BALL/STRUCTURE/fragmentDB.h>
#include <BALL/STRUCTURE/peptides.h>

#include <vector>
#include <iostream>
#include "version.h"

using namespace std;
using namespace BALL;

void usage (const char *progname);

int main (int argc, char **argv)
{
	CommandlineParser parpars("PeptideBuilder", "build a peptide  ", VERSION, String(__DATE__), "Preparation");
	parpars.registerParameter("i", "input torsion-file", INFILE, true);
	parpars.registerParameter("o", "peptide output pdb-file", OUTFILE, true);
	//parpars.registerParameter("peptide_name", "name of the peptide", STRING, false);

	String man = "This tool creates a peptide by a given torsion file. The amino acids shall be given in three letter code, the phi, psi, and omega angles shall be given in degree.\n\nExample:\n\n# aa   phi    psi   omega\n\nA    -180    140\n\nC    -180    180\n\nG    -90    -140\n\nP    -65    -40       0   # cis\n\nT    -120    -90\n\nP    -78     146     180  # trans";

	parpars.setToolManual(man);
	parpars.setSupportedFormats("i", "txt");
	parpars.setSupportedFormats("o", "pdb");
	parpars.parse(argc, argv);

	// initialize the peptide builder
	BALL::Peptides::PeptideBuilder* pb = new BALL::Peptides::PeptideBuilder;

	// "link" the fragment db for adding missing information
  FragmentDB fdb("");
  pb->setFragmentDB(&fdb);

	// read the torsion file (format AA, PHI, PSI)
	// e.g. ALA 109 65
	LineBasedFile torsion_file(parpars.get("i"), std::ios::in);
	vector<String> fields;
	while (torsion_file.LineBasedFile::readLine())
	{
		// get the line
		String aa_torsion = torsion_file.getLine();

		if ((aa_torsion.countFields(" ")>0) && (aa_torsion(0,1) != "#"))
		{
			fields.clear();
			aa_torsion.split(fields);

			// split and check
			// either expect a line
			//    G
			//    A    -180    140
			// or
			//    A    -180    140   180 # some comment
			if (   (fields.size() != 1)
					&& (   (fields.size()<3)
					    || ((fields.size()>3) && (fields[3] != "#") && (fields[4] != "#")) ))
			{
				Log.error() << "Error in while reading file " << parpars.get("i") << " in line " << aa_torsion << endl;
			}

			String aa = fields[0];

			// assume a helix if no angles given
			float phi = 300;
			float psi = 310;
			float omega = 0.;

			if (fields.size()>1)
			{
				phi = fields[1].toFloat();
				psi = fields[2].toFloat();
			}

			if ((fields.size()>4) && (fields[3] != "#"))
				omega = fields[3].toFloat();

			char test_aa = aa.toChar();

{'fraction_non_alphanumeric': 0.16903326201128185, 'fraction_numerical': 0.026259482590935617, 'mean_word_length': 3.372448979591837, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 30, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7047763', 'n_tokens_mistral': 2111, 'n_tokens_neox': 1825, 'n_words': 472}