Difference between revisions of "CompSciWeek3"

From Predictive Chemistry
Jump to: navigation, search
m (Homework 2 - due Monday, Sept. 15)
(Homework 2 - due Monday, Sept. 15)
 
(6 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
== Reading Assignment ==
 
== Reading Assignment ==
  +
* Beginning Python, Chapter 6
 
* Algorithms, Chapters 1-2
 
* Algorithms, Chapters 1-2
 
** focus on tree data structures (formal complexity next week)
 
** focus on tree data structures (formal complexity next week)
Line 6: Line 7:
 
= Class 1: Intermediate shell utilities =
 
= Class 1: Intermediate shell utilities =
 
* commands
 
* commands
** cat
 
  +
** man/info <-> help()
** grep
 
  +
** ls <-> dir()
** sort
 
  +
** cat <-> print
** head / tail
 
  +
** grep <-> string.find()
** tr, sed
 
  +
** sort <-> list.sort()
  +
** head / tail <-> list.__slice__ (i.e. l[:10])
  +
** tr, sed <-> string.replace()
 
** find
 
** find
 
** w, top, last
 
** w, top, last
 
* shell variables
 
* shell variables
 
* control flow
 
* control flow
** pipes, &&, ||
 
  +
** shell functions -- f() { commands; }
** for loops
 
  +
** pipes, redirection, &&, || -- a | b, a && b, a || b
  +
** for, while loops -- for i in 1 2 3; do ... done, for((i=0; i<$n; i++)); do ... done
  +
  +
References:
  +
* [https://docs.python.org/3/ Python Syntax]
  +
* [http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html Bash Syntax]
  +
* [http://sed.sourceforge.net/sed1line.txt Sed One-Liners]
   
 
= Class 2: Python vs. shell =
 
= Class 2: Python vs. shell =
Line 25: Line 34:
 
* Graphs
 
* Graphs
   
= Homework 2 - due Monday, Sept. 15 =
+
= Homework 2 - due Tuesday, Sept. 16 =
  +
  +
Since the due date was pushed back, re-submitted homework will be accepted in place of the original. As a reminder, all homework must be done on your own. Send the homework as a single txt file attachment with the subject line "Sci Comp HW2". If you send a pdf, format it using the script [[Code:text2pdf]].
  +
 
* Coding problems:
 
* Coding problems:
** Write a loop to sum 100 random numbers (import random, random.random()) using each of the following control structures: for, while, list and `tuple` comprehension.
+
** Write a loop to sum 100 random numbers (import random, random.random()) using each of the following control structures: for, while, list and `tuple` comprehension. The first two can generate numbers in the loop, the last two must create iterators / generators and can use the python builtin `sum' function.
** Write a shell loop to save 100 numbers from $RANDOM to a file, writing one number per line.
+
** Write a shell loop to save 100 numbers from $RANDOM to a file, writing one number per line. (hint: use the shell append re-direction, '''>>''' instead of the usual re-direction '''>''')
** Write a shell loop to sum files with 1 number per line.
+
** Write a shell loop to sum files with 1 number per line. -- use shell math expressions, like a=$(($a*12))
 
** Write python and shell programs to print the smallest 10 numbers from such a file.
 
** Write python and shell programs to print the smallest 10 numbers from such a file.
 
** Write a text processing script using sed to get the numbers for the following quantities from [[File:multiwfn.txt]]
 
** Write a text processing script using sed to get the numbers for the following quantities from [[File:multiwfn.txt]]
 
**# '''Basin electric monopole moment:''' (1 number for ea. line)
 
**# '''Basin electric monopole moment:''' (1 number for ea. line)
**# '''Basin electric dipole moment:''' and '''Basin electron contribution to molecular dipole moment:''' (3 numbers from ea. line tagged X=, etc)
+
**# '''Basin electric dipole moment:''' and '''Basin electron contribution to molecular dipole moment:''' (3 numbers from ea. line) The input is tagged X=, etc, the output should have only numbers.
  +
*** (Clarification) The output (if run) would be one file with all the "monopole" numbers, 1 per line, another with all the "dipole" numbers, 3 per line. I just want the code, not the output.

Latest revision as of 08:09, 15 September 2014

Reading Assignment

  • Beginning Python, Chapter 6
  • Algorithms, Chapters 1-2
    • focus on tree data structures (formal complexity next week)
    • ignore python 'Class' for now

Class 1: Intermediate shell utilities

  • commands
    • man/info <-> help()
    • ls <-> dir()
    • cat <-> print
    • grep <-> string.find()
    • sort <-> list.sort()
    • head / tail <-> list.__slice__ (i.e. l[:10])
    • tr, sed <-> string.replace()
    • find
    • w, top, last
  • shell variables
  • control flow
    • shell functions -- f() { commands; }
    • pipes, redirection, &&, || -- a | b, a && b, a || b
    • for, while loops -- for i in 1 2 3; do ... done, for((i=0; i<$n; i++)); do ... done

References:

Class 2: Python vs. shell

  • Reading / Writing Files
  • Advanced control structures (list comprehensions)
  • Code profiling
  • Hash tables
  • Graphs

Homework 2 - due Tuesday, Sept. 16

Since the due date was pushed back, re-submitted homework will be accepted in place of the original. As a reminder, all homework must be done on your own. Send the homework as a single txt file attachment with the subject line "Sci Comp HW2". If you send a pdf, format it using the script Code:text2pdf.

  • Coding problems:
    • Write a loop to sum 100 random numbers (import random, random.random()) using each of the following control structures: for, while, list and `tuple` comprehension. The first two can generate numbers in the loop, the last two must create iterators / generators and can use the python builtin `sum' function.
    • Write a shell loop to save 100 numbers from $RANDOM to a file, writing one number per line. (hint: use the shell append re-direction, >> instead of the usual re-direction >)
    • Write a shell loop to sum files with 1 number per line. -- use shell math expressions, like a=$(($a*12))
    • Write python and shell programs to print the smallest 10 numbers from such a file.
    • Write a text processing script using sed to get the numbers for the following quantities from File:Multiwfn.txt
      1. Basin electric monopole moment: (1 number for ea. line)
      2. Basin electric dipole moment: and Basin electron contribution to molecular dipole moment: (3 numbers from ea. line) The input is tagged X=, etc, the output should have only numbers.
      • (Clarification) The output (if run) would be one file with all the "monopole" numbers, 1 per line, another with all the "dipole" numbers, 3 per line. I just want the code, not the output.