<commit_before>#!/bin/bash


WORKDIR=$PWD

run=$1 		  # Can be run1 run2 run3 run4 ...
simtime=$2		  # Can be 000-050, 000-0500, 100-150 ...
cluster=$3        # Can be CTnI_hmr CTnI_runs CTnT_hmr CTnT_runs
phosphotype=$4    # Can be S1P or SEP


WORKDIR=$PWD
printf "\nCurrent directory is %s\n" $WORKDIR
DESTINATION=${WORKDIR}/${cluster}/${run}/${phosphotype}

printf "The destination directory is %s\n\n" $DESTINATION

if [ -d "$DESTINATION" ]; then 
	printf "The directory exists\n\n"
else
	printf "The destination directory does not exist\n"
	printf "\nPlease check the arguments
--------------------------------
Run:\t\t\t%s\nSim:\t\t\t%s\nCluster:\t\t%s\nPhosphorylation type:\t%s
--------------------------------\n" ${run} ${simtime} ${cluster} ${phosphotype}
	printf "Exiting now...\n\n"
	exit 1
fi



cd ${DESTINATION}


cpptraj <<- EOF
	parm ./repstr.c0_phosS1P_nowat.prmtop
	trajin ./05_Prod*.nc
	# Fit to first frame, create average structure, save coordinates
	rms first
	average crdset average_structure
	createcrd loaded_trajs
	run
	#Fit the frames to the previously averaged structure, using the backbone
	crdaction loaded_trajs rms ref average_structure @CA,C,O,N,H

	#Calculate the coordinate covariance matrix
	crdaction loaded_trajs matrix covar name matrix_covar @CA,C,O,N,H

	#Diagonalize the cov matrix and get first 3 eigenvectors
	runanalysis diagmatrix matrix_covar out \
		${DESTINATION}/evecs-ca_${cluster}.${simtime}ns.dat vecs 200 name \
		myEvecs @CA,C,O,N,H

	# Project fit and saved coordinates along eigenvectors
	crdaction loaded_trajs projection PROJECT modes myEvecs beg 1 end 3 \
		@CA,C,O,N,H out ${DESTINATION}/myevecs_${cluster}.${simtime}ns.dat

	# Make normalized histogram of the 3 calculated projections
	hist PROJECT:1 bins 100 out \
		${DESTINATION}/${cluster}_${simtime}-hist.dat norm name PROJECT-1

	hist PROJECT:2 bins 100 out \
		${DESTINATION}/${cluster}_${simtime}-hist.dat norm name PROJECT-2

	hist PROJECT:3 bins 100 out \
		${DESTINATION}/${cluster}_${simtime}-hist.dat norm name PROJECT-3

	# Run and clear
	run
	clear all

	# Read the file with the eigenvectors
	readdata ${DESTINATION}/evecs-ca_${cluster}.${simtime}ns.dat \
		name Evecs

	# Create a topology for the backbone only
	parm ${DESTINATION}/repstr.c0_phosS1P_nowat.prmtop
	parmstrip !(@CA,C,O,N,H)
	parmwrite out ${DESTINATION}/repstr.c0_phosS1P_nowat_striped.prmtop 

	#Create a .nc trajectory with the modes of motion of the 1st PC
	runanalysis modes name Evecs trajout ${DESTINATION}/${cluster}_${simtime}_1PCA.nc \
		pcmin -100 pcmax 100 tmode 1 trajoutmask @CA,C,O,N,H trajoutfmt netcdf

EOF<commit_msg>Modified pca_enhanced.sh to be able to use it more generally. It should be used directly in the directory where the trajectories and the prmtop is. Now you can choose the name directly<commit_after>#!/bin/bash

# Advanced analysis of PCA with cpptraj
# Must run on the directory where the trajectories
# and the prmtop are. 





simtime=$1		  # Can be 000-050, 000-0500, 100-150 ...
name=$2        # Can be CTnI_hmr CTnI_runs CTnT_hmr CTnT_runs with _run1 _run2 ...
								# Example: CTnI_hmr-run3-S1P
								# Example: WT-run3

prmtop=$3
trajs=$4



cpptraj <<- EOF
	parm ./${prmtop}
	trajin ./${trajs}
	# Fit to first frame, create average structure, save coordinates
	rms first
	average crdset average_structure
	createcrd loaded_trajs
	run
	#Fit the frames to the previously averaged structure, using the backbone
	crdaction loaded_trajs rms ref average_structure @CA,C,O,N,H

	#Calculate the coordinate covariance matrix
	crdaction loaded_trajs matrix covar name matrix_covar @CA,C,O,N,H

	#Diagonalize the cov matrix and get first 3 eigenvectors
	runanalysis diagmatrix matrix_covar out \
		./evecs-ca_${name}.${simtime}ns.dat vecs 200 name \
		myEvecs

	# Project fit and saved coordinates along eigenvectors
	crdaction loaded_trajs projection PROJECT modes myEvecs beg 1 end 3 \
		@CA,C,O,N,H out ./myevecs_${name}.${simtime}ns.dat

	# Make normalized histogram of the 3 calculated projections
	hist PROJECT:1 bins 100 out \
		./${name}_${simtime}-hist.dat norm name PROJECT-1

	hist PROJECT:2 bins 100 out \
		./${name}_${simtime}-hist.dat norm name PROJECT-2

	hist PROJECT:3 bins 100 out \
		./${name}_${simtime}-hist.dat norm name PROJECT-3

	# Run and clear
	run
	clear all

	# Read the file with the eigenvectors
	readdata ./evecs-ca_${name}.${simtime}ns.dat \
		name Evecs

	# Create a topology for the backbone only
	parm ./${prmtop}
	parmstrip !(@CA,C,O,N,H)
	parmwrite out ./repstr.c0_phosS1P_nowat_backbone.prmtop 

	#Create a .nc trajectory with the modes of motion of the 1st PC
	runanalysis modes name Evecs trajout ./${name}_${simtime}_1PCA.nc \
		pcmin -100 pcmax 100 tmode 1 trajoutmask @CA,C,O,N,H trajoutfmt netcdf

EOF
{'fraction_non_alphanumeric': 0.11464435146443515, 'fraction_numerical': 0.02698744769874477, 'mean_word_length': 3.8686354378818737, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, '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': '1858223', 'n_tokens_mistral': 1909, 'n_tokens_neox': 1692, 'n_words': 521}