Skip to content

001A IO and Table Manipulation

Jordy Homing Lam edited this page Sep 22, 2024 · 15 revisions

Motivation

You are given a CSV file, you want to script with respect to data on this file. How to do it in ICM? Some reasons to motivate this tedious exercise:

  • Your client only uses GUI, they want a nice Excel-like layout with one-click output that is Excel-ready.
  • You want to access ICM-exclusive functionality e.g. internal coordinate modelling.
  • You are only allowed to code on ICM, because your company cannot take risk in using other software with tricky open source licenses. ICM sessions also come with encryption with password.

So, how to do it?

Matrix

Assume we have opened a sdf by mouse clicks; it displays in an Excel-ready format. Clipboard copy paste can be done through mouse when you are in GUI. Some command lines to do it.

  • open_dir = Path() + "/t.sdf" - This specifies the current path and the filename
  • read table mol open_dir - It can also read a csv

Organise a Matrix

Now, we want to organise this matrix as a ICM Table to facilitate operations on this matrix. A table in ICM is not just a matrix. It is a table linked to buttons in the GUI, which allows users to do descriptive statistics and basic plots (e.g. Histogram, Line, Scatter) like the Microsoft Excel.

  • sort t.Score reverse- This sorts column Score in descending order
  • rename column t "Max_min_"//"Max_min_" name = "Comment"//"Comment"- This rename column "Max_min" as "Comment"

Note that column name with space e.g. "PTH1R Position" will be renamed as "PTH1R_Position", even though we can still read the space on screen (the Excel-like display).

  • The altered column name space can be checked from the terminal "t." Tab Tab Tab.
  • Column name as recognized by ICM syntax below will NOT take in the space nor underscore, it will be t.PTH1RPosition
  • A follow-up thread on this behavior. "Max(Min)" is renamed as "Max_min_".

Operate on Matrix t

  • t.A - This will print the whole column A. It is also the way to call data from that column.
  • Nof(t) - This gives the number of rows in the matrix.
  • add column t 5.*Log(Abs(t.Score),2)+Log(Abs(t.CScore),2) index=3 name="Score2" - This adds a new column called "Score2"
  • delete t[5000: Nof(t)] - Delete from row 5000 onwards.
  • delete t.a == 2 - Delete where column a value == 2

Example. Energy of residues as a table

  • ``
  • set object a_5w0p. - set a_5w0p as the current object
  • (a_/sep | a_tpo) - Phosphorylated residues
  • `` - Put sum of energy at those residues as a table.
  • `` - rename table t as the objects name

Example. Iterating on a chemical table in GUI.

Just a for loop. I copied t7sk2Un20230907Hits to PREVIOUSTABLE with two columns Purchased and RaviRound01

GUI.autoSave="off"
PREVIOUSTABLE=t7sk2Un20230907Hits
for i = 1, Nof(PREVIOUSTABLE)
   
  if (PREVIOUSTABLE.Purchased[i]==0) then
       continue
  endif 
  #if (PREVIOUSTABLE.RaviRound01[i]==0) then
  #     continue
  #endif
  if (PREVIOUSTABLE.RaviRound01Percent[i] < 0.15) then
       continue
  endif



	print "ICM-shell proudly announces that i=", i, PREVIOUSTABLE.Purchased[i] , PREVIOUSTABLE.RaviRound01[i]

  # record ix
  iiixxx=PREVIOUSTABLE.IX[i]
  briid=PREVIOUSTABLE.BRI_ID[i]

	# click on the table and get a  new moleucle
  dsChemTemp_new "PREVIOUSTABLE" i yes

	# select the current mol 
  as_graph=a_
  
  # convert to icm object
  as2_out = Obj( a_. & a_!ICM. )
  convert3Dto3D as2_out no yes yes

	# select the current mol 
  as_graph=a_


	#delete tmp
  delete a_tmp.

  # scan hit list for apf
  APFi="APF_"+String(5,0,briid)


  add column tmp_table Rarray(Nof(tmp_table),0.) index=2 name=APFi delete comment="make real column"  
  scanCalcHitListProperty "tmp_table" "macro scanEvalAPFsimil" APFi

	#delete tmp
  delete a_tmp.

  s_out = "/mnt/data0/homingla/MessLab/Project-GAT1Vsynthes/20240715/Postprocessing/my7sk2o/run/processing_files/my7sk2o_my7sk2o_2comp_final_energy.icb"
  writeProject s_out s_currentProject!=""

  print "Done", APFi, briid

endfor 
delete a_.m


Extracting

# Extracted_APF_21163 = tmp_table[Index(tmp_table.APF_21163 < -100)]

  
GUI.autoSave="off"
PREVIOUSTABLE=t7sk2Un20230907Hits

# Get a new column
add column PREVIOUSTABLE Rarray(Nof(PREVIOUSTABLE),0.) index=2 name="NofClash" delete comment="make real column"  
add column PREVIOUSTABLE Rarray(Nof(PREVIOUSTABLE),0.) index=2 name="NofHbond" delete comment="make real column"  

for i = 1, Nof(PREVIOUSTABLE)
   




	print "ICM-shell proudly announces that i=", i, PREVIOUSTABLE.Purchased[i] , PREVIOUSTABLE.RaviRound01[i]

  # record ix
  iiixxx=PREVIOUSTABLE.IX[i]
  briid=PREVIOUSTABLE.BRI_ID[i]

	# click on the table and get a  new moleucle
  dsChemTemp_new "PREVIOUSTABLE" i yes

	# select the current mol 
  as_graph=a_
  
  # convert to icm object
  as2_out = Obj( a_. & a_!ICM. )
  convert3Dto3D as2_out no yes yes

	# select the current mol 
  as_graph=a_


	#delete tmp
  delete a_tmp.
  move a_.m a_my7sk2o_rec.
  
  #add column tmp_table Rarray(Nof(tmp_table),0.) index=2 name=APFi delete comment="make real column"  #
  #scanCalcHitListProperty "tmp_table" "macro scanEvalAPFsimil" APFi
  show clash mute a_my7sk2o_rec. a_.m
  PREVIOUSTABLE.NofClash[i] = Real(i_out)

  show hbond mute a_my7sk2o_rec. a_.m
  PREVIOUSTABLE.NofHbond[i] = Real(i_out)

	#delete tmp
  delete a_tmp.
  delete a_.m

endfor


IO

File Opening

Helpful commands to open files of different formats. These can be easily checked/learnt from recording mouse-clicks.

  • PDB, OB

  • SDF - read table mol "XXX.sdf"

  • CSV CSV with header

  • ICB

  • ICM

File Saving

Again, these commands depends on machine (Linux/Windows/Mac). I only work out Linux/Windows by mouse-clicks.

  • writeProject "D:\\Downloads\\5w0pNoT506_051.icb" no
  • write table mol t open_dir+"/t_5000.sdf"
Clone this wiki locally