Academic Tutorials

English | French | Portugese | German | Italian
Home Advertise Payments Recommended Websites Interview Questions FAQs
News Source Codes E-Books Downloads Jobs Web Hosting

Apple Script
Introduction to Applescript
Applescript and UNIX commands
Reading, Writing and using Lists
Line endings and ChemDraw
Building a substructure searchable database
Rendering the chemical structures
Printing the clipboard
Embedding chemical information in image files

HTML Tutorials
HTML Tutorial
XHTML Tutorial
CSS Tutorial
TCP/IP Tutorial
CSS 1.0
CSS 2.0
XML Tutorials
XML Tutorial
XSL Tutorial
XSLT Tutorial
DTD Tutorial
Schema Tutorial
XForms Tutorial
XSL-FO Tutorial
XML DOM Tutorial
XLink Tutorial
XQuery Tutorial
XPath Tutorial
XPointer Tutorial
RDF Tutorial
SOAP Tutorial
WSDL Tutorial
RSS Tutorial
WAP Tutorial
Web Services Tutorial
Browser Scripting
JavaScript Tutorial
VBScript Tutorial
DHTML Tutorial
HTML DOM Tutorial
WMLScript Tutorial
E4X Tutorial
Server Scripting
ASP Tutorial
PERL Tutorial
SQL Tutorial
ADO Tutorial
Apple Script
PL/SQL Tutorial
SQL Server
.NET (dotnet)
.Net Mobile
C# : C Sharp
SVG Tutorial
Flash Tutorial
Media Tutorial
SMIL Tutorial
Photoshop Tutorial
Gimp Tutorial
Gnuplot Programming
GIF Animation Tutorial
Scientific Visualization Tutorial
Web Building
Web Browsers
Web Hosting
W3C Tutorial
Web Building
Web Quality
Web Semantic
Web Careers
Weblogic Tutorial
Web Site Hosting
Domain Name
Java Tutorials
Java Tutorial
JSP Tutorial
Servlets Tutorial
Struts Tutorial
EJB Tutorial
JMS Tutorial
JMX Tutorial
Programming Langauges
C Tutorial
C++ Tutorial
Visual Basic Tutorial
Data Structures Using C
Assembly Language
Forth Programming
Lisp Programming
Data Warehousing
CGI Programming
Emacs Tutorial
Soft Skills
Communication Skills
Time Management
Project Management
Team Work
Leadership Skills
Corporate Communication
Negotiation Skills
Database Tutorials
Operating System
Software Testing
SAP Module
Business Warehousing
SAP Basis
Material Management
Sales & Distribution
Human Resource
Customer Relationship Management
Production and Planning
Networking Programming
Corba Tutorial
Networking Tutorial
Microsoft Office
Microsoft Word
Microsoft Outlook
Microsoft PowerPoint
Microsoft Publisher
Microsoft Excel
Microsoft Front Page
Microsoft InfoPath
Microsoft Access
Financial Accounting
Managerial Accounting
Network Sites

Line endings and ChemDraw

Previoushome Next

Line endings and ChemDraw
As was mentioned in the previous tutorial one potential problem is SMILES often arrive as UNIX files, and there are two different line ending conventions in Mac OS X: Mac-style (lines end with return: "\r" or ASCII ) and Unix-style (lines end with line-feed: "\n" or ASCII ), so if we try to read a Unix file available here

We need to alter the previous script to do two things, firstly detect the line-endings to identify whether the file is a UNIX or Mac file type, we then need to use the appropriate deliminator in both the import and write to file.
The first part we do by reading in part of the file (100 characters) as shown in the script below, we then see if the result contain a line feed (ASCII).

set {lf, return} to {ASCII character 10, ASCII character 13}

set theFile to (choose file with prompt "Select the file:") as alias

set the_result to read theFile for 100
if (the_result contains lf) then
set delim to lf
set delim_1 to "Unix File"
else if (the_result contains return) then
set delim to return
set delim_1 to "Mac File"
end if
display dialog delim_1

We can then replace the deliminator with the variable "delim" for both the read

set theData to read theFile using delimiter delim

and add the correct line-endings to the output

set mol_list to mol_list & delim

The full script now looks like this, it will now read either UNIX or Mac files and then write the output in the corresponding UNIX or Mac format. Some people will no doubt have noticed that the output is test2.smi, this is the correct file extension for SMILES files, unfortunately the ".smi" extension also corresponds to a "self-mounting image".

set mol_list to {}
set the_compounds to {}
set all_mols_list to {}
set mol_props_list to {}
set theData to {}

set {lf, return} to {ASCII character 10, ASCII character 13}

set theFile to (choose file with prompt "Select the file:") as alias

set the_file_path to GetParentPath(theFile)

set theSaveFile to the_file_path & "test2.smi"

--display dialog theSaveFile
set the_result to read theFile for 100
if (the_result contains lf) then
set delim to lf
set delim_1 to "Unix File"
else if (the_result contains return) then
set delim to return
set delim_1 to "Mac File"
end if
display dialog delim_1

open for access theFile
--UNIX file
--set theData to read theFile using delimiter "\n"
set theData to read theFile using delimiter delim
close access theFile

set text item delimiters to tab
repeat with i from 1 to count of items in theData
set theLine to text items of item i of theData
copy theLine to the end of mol_list
end repeat
set text item delimiters to ""

set num_compounds to count of items in mol_list

repeat with i from 1 to num_compounds

set mol_props_list to {}
set the_compound to item i of mol_list
set the_SMILES to item 1 of the_compound
set the_name to item 2 of the_compound
--display dialog the_SMILES
--display dialog the_name
set the clipboard to the_SMILES

tell application "CS ChemDraw Ultra"


if enabled of menu item "Paste" then do menu item "SMILES" of menu "Paste Special" of menu "Edit"

set the_CD_SMILES to SMILES of selection
set Elem_Anal to Elemental Analysis of selection
set Exact_mass to Exact Mass of selection
set Mol_Form to Molecular Formula of selection
set Mol_weight to Molecular Weight of selection

copy the_SMILES to the end of mol_props_list
copy the_name to the end of mol_props_list
copy the_CD_SMILES to the end of mol_props_list
copy Elem_Anal to the end of mol_props_list
copy Exact_mass to the end of mol_props_list
copy Mol_Form to the end of mol_props_list
copy Mol_weight to the end of mol_props_list

if enabled of menu item "Paste" then do menu item "Clear" of menu "Edit"
--display dialog (item 3 of mol_props_list)
end tell
copy mol_props_list to the end of all_mols_list
end repeat

repeat with i from 1 to num_compounds
set mol_list to item i of all_mols_list
-- convert list to text
set old_delim to AppleScript's text item delimiters
set AppleScript's text item delimiters to tab
set mol_list to mol_list as text
--set mol_list to mol_list & "\n" needs UNIX line endings
set mol_list to mol_list & delim
set AppleScript's text item delimiters to old_delim
my write_to_file(mol_list, theSaveFile, true)
end repeat

on GetParentPath(theFile)
tell application "Finder" to return container of theFile as text
end GetParentPath

on write_to_file(this_data, target_file, append_data)
set the target_file to the target_file as text
set the open_target_file to
open for access file target_file with write permission
if append_data is false then
set eof of the open_target_file to 0
write this_data to the open_target_file starting at eof
close access the open_target_file
return true
on error
close access file target_file
end try
return false
end try
end write_to_file

Errors and Omissions in the file

Sometimes files contain SMILES strings but do not contain the corresponding name (or molecule ID) at the moment the script will fail at the point:

set the_name to item 2 of the_compound

Since there will be no item 2. We can avoid this problem by modifying the script as shown below. First try to extract the name if present then if there is no name construct a name based on the position of the molecule in the file (e.g. the fifth molecule will be called molecule_5).
set the_name to item 2 of the_compound
--If no name set name to molecule and number
end try
if the_name = "" then
set the_name to "molecule_" & i
end if


Be the first one to comment on this page.

  Apple Script eBooks

No eBooks on Apple Script could be found as of now.

 Apple Script FAQs
More Links » »
 Apple Script Interview Questions
More Links » »
 Apple Script Articles

No Apple Script Articles could be found as of now.

 Apple Script News

No News on Apple Script could be found as of now.

 Apple Script Jobs

No Apple Script Articles could be found as of now.

Share And Enjoy:These icons link to social bookmarking sites where readers can share and discover new web pages.
  • blinkbits
  • BlinkList
  • blogmarks
  • co.mments
  • connotea
  • digg
  • Fark
  • feedmelinks
  • Furl
  • LinkaGoGo
  • Ma.gnolia
  • NewsVine
  • Netvouz
  • RawSugar
  • Reddit
  • scuttle
  • Shadows
  • Simpy
  • Smarking
  • Spurl
  • TailRank
  • Wists
  • YahooMyWeb

Previoushome Next

Keywords: applescript language,applescript documentation,applescript manual,applescript guide,applescript application

HTML Quizzes
CSS Quiz
CSS 1.0 Quiz
CSS 2.0 Quiz
XML Quizzes
XML Quiz
XSL Quiz
DTD Quiz
Schema Quiz
XForms Quiz
XLink Quiz
XQuery Quiz
XPath Quiz
XPointer Quiz
RDF Quiz
RSS Quiz
WAP Quiz
Web Services Quiz
Browser Scripting Quizzes
JavaScript Quiz
VBScript Quiz
WMLScript Quiz
E4X Quiz
Server Scripting Quizzes
ASP Quiz
SQL Quiz
ADO Quiz
CVS Quiz
Python Quiz
Apple Script Quiz
SQL Server Quiz
PHP Quiz
.NET (dotnet) Quizzes
Microsoft.Net Quiz
ASP.Net Quiz
.Net Mobile Quiz
C# : C Sharp Quiz
VC++ Quiz
Multimedia Quizzes
SVG Quiz
Flash Quiz
Media Quiz
Photoshop Quiz
Gimp Quiz
Matlab Quiz
Gnuplot Programming Quiz
GIF Animation Quiz
Scientific Visualization Quiz
Graphics Quiz
Web Building Quizzes
Web Browsers Quiz
Web Hosting Quiz
W3C Quiz
Web Building Quiz
Web Quality Quiz
Web Semantic Quiz
Web Careers Quiz
Weblogic Quiz
SEO Quiz
Web Site Hosting Quiz
Domain Name Quiz
Java Quizzes
Java Quiz
JSP Quiz
Servlets Quiz
Struts Quiz
EJB Quiz
JMS Quiz
JMX Quiz
Eclipse Quiz
J2ME Quiz
Programming Langauges Quizzes
C Quiz
C++ Quiz
Visual Basic Quiz
Data Structures Using C Quiz
Cobol Quiz
Assembly Language Quiz
Mainframe Quiz
Forth Programming Quiz
Lisp Programming Quiz
Pascal Quiz
Delphi Quiz
Fortran Quiz
OOPs Quiz
Data Warehousing Quiz
CGI Programming Quiz
Emacs Quiz
Gnome Quiz
ILU Quiz
Soft Skills Quizzes
Communication Skills Quiz
Time Management Quiz
Project Management Quiz
Team Work Quiz
Leadership Skills Quiz
Corporate Communication Quiz
Negotiation Skills Quiz
Database Quizzes
Oracle Quiz
MySQL Quiz
Operating System Quizzes
BSD Quiz
Symbian Quiz
Unix Quiz
Internet Quiz
IP-Masquerading Quiz
IPC Quiz
Software Testing Quizzes
Testing Quiz
Firewalls Quiz
SAP Module Quizzes
ERP Quiz
Business Warehousing Quiz
SAP Basis Quiz
Material Management Quiz
Sales & Distribution Quiz
Human Resource Quiz
Netweaver Quiz
Customer Relationship Management Quiz
Production and Planning Quiz
Networking Programming Quizzes
Corba Quiz
Networking Quiz
Microsoft Office Quizzes
Microsoft Word Quiz
Microsoft Outlook Quiz
Microsoft PowerPoint Quiz
Microsoft Publisher Quiz
Microsoft Excel Quiz
Microsoft Front Page Quiz
Microsoft InfoPath Quiz
Microsoft Access Quiz
Accounting Quizzes
Financial Accounting Quiz
Managerial Accounting Quiz
Testimonials | Contact Us | Link to Us | Site Map
Copyright ? 2008. Academic All rights reserved Privacy Policies | About Us
Our Portals : Academic Tutorials | Best eBooksworld | Beyond Stats | City Details | Interview Questions | Discussions World | Excellent Mobiles | Free Bangalore | Give Me The Code | Gog Logo | Indian Free Ads | Jobs Assist | New Interview Questions | One Stop FAQs | One Stop GATE | One Stop GRE | One Stop IAS | One Stop MBA | One Stop SAP | One Stop Testing | Webhosting in India | Dedicated Server in India | Sirf Dosti | Source Codes World | Tasty Food | Tech Archive | Testing Interview Questions | Tests World | The Galz | Top Masala | Vyom | Vyom eBooks | Vyom International | Vyom Links | Vyoms | Vyom World | Important Websites
Copyright ? 2003-2024 Vyom Technosoft Pvt. Ltd., All Rights Reserved.