Category Archives: Uncategorized

Python Single-Point Geometry Energy Script Update

Continued from a previous post.

As I created my first completed version of the python script, I learned several things about python.

One thing I learned was how file handles work. With the function:

def find_parameters(file_handle):
    for l in file_handle:
         if l.startswith(" #"):
             return l.rstrip()

I was running into an error in which I received the message, Nonetype has no attribute…, meaning that my code was trying to use nothing as its input for functions that were looking for strings. That was after I looped through the file handle for a find function. I learned that looping through a file handle leaves the “cursor” at the end of the file handle, so that the very next use of the file handle would start at the end of the file handle. To reset the “cursor” at the beginning of the file handle, I need to call file_handle.seek(0) after each iteration, as follows:

def find_parameters(file_handle):
    file_handle.seek(0)
    for l in file_handle:
         if l.startswith(" #"):
             return l.rstrip()

Here is a Stack Overflow thread with an explanation.

Another thing I learned had to do with the difference between the .append() and .extend() functions. After some searching and consultation with Prof. Kennerly, I realized that that was because I called .extend() rather than .append(). I was trying to add a string as an item to an empty list, and the .extend() function treated the string itself as some sort of list. Using the .append() function instead kept the string as a string and simply added it as a value to the list. Here is a Stack Overflow thread with more discussion of the difference between .append() and .extend().

One more error that I do not understand but have since overcome has to do with Unicode. I had an interesting hour or so in which I got long text files of Sanskrit and other unexpected languages instead of my output data, when I opened my results text file in Wordpad. Other text editors, such as Microsoft Word, had no trouble reading the text files. I think that this error had something to do with the .extend() function, but I’m not sure. I recall that the error went away after I corrected my code to use .append() instead of .extend(), but that may not have been the direct source of the error. Further investigation of the Unicode issue is needed for a better understanding of it.

Often error messages may not describe the cause of the problem, but give clues of where the problem is. That is why many different error messages popped up when I had a more fundamental issue somewhere else in the script. In addition, as Prof. Kennerly says, computers always do what you tell them. So, the Sanskrit output made sense, given the code I wrote. To fix problems with the script, I needed more understanding of what certain functions did and how python and Wordpad read files.

I used IDLE on a Windows computer to edit and run my script.

P.S. WordPress is not good at allowing indentations or extra spaces. I have to use a keyword &+nbsp; (without the +) to create spaces in the text editor, and all instances of it disappear if I switch to the visual editor. I think this is an issue with HTML, and I read that I would have to use CSS to allow indents in WordPress. This is an annoying problem, and I am trying to get around it for future posts where I show snippets of code.

4 Comments

Filed under Uncategorized

Accessing Skidmore’s datastor server and our KennerlyResearch shared folder

Our research group has a special folder on the Skidmore server “datastor” where we all keep things we’re working on and sharing.

On Mac, connect to the server smb://datastor.skidmore.edu

On Windows, connect to //datastor.skidmore.edu

If you’re on a Skidmore computer, there is likely a “Datastor” icon on your desktop that will connect you automatically.

After you connect to datastor, look for the “Netshare” directory and then the subdirectory “KennerlyResearch”.

 

If this is your first time doing this, you can follow these instructions at the link below for more details.  Also, you will need to ask me to add your Skidmore username for permission to read and write files in KennerlyResearch.

On Windows:  https://help.skidmore.edu/index.php?/Knowledgebase/Article/View/33/3/connecting-to-vpn-in-windows-7-pc

On Mac: https://help.skidmore.edu/index.php?/Knowledgebase/Article/View/34/0/connecting-to-vpn-in-osx-mac

If you are on-campus, it is quick and easy to get access to the folder.

If you are off-campus, you will need to install VPN software called “Cisco AnyConnect” to securely connect back to Skidmore’s intranet.  The links above have instructions for doing that for both Windows and Mac.

Leave a Comment

Filed under Uncategorized