锘??xml version="1.0" encoding="utf-8" standalone="yes"?> Availability Download
As an example, the following 2D representation of caffeine in PNG (Portable Network Graphics) format was created from the corresponding MDL molfile (PubChem CID 2519), using mol2ps in combination with Ghostscript:
As input files, MDL molfiles and SD files (*.mol, *.sdf; 2D and 3D), Alchemy molfiles (*.mol), and Sybyl mol2 files (*.mol2) are accepted by mol2ps, the preferred format is the MDL molfile format. At present, it is not intended to extend the number of supported input file formats, as there are powerful file format converters available, such as OpenBabel.
The main purpose of mol2ps is to create small, but high-quality 2D pictures of molecules for display on web pages. Especially for web-based molecular structure databases it is quite useful to have pre-built pictures for display in hitlists instead of invoking browser plugins, Java applets, or server-side programs for display of the individual structures. A description of how such structure databases can be created with free software is given here.
It is written in Pascal and it was compiled with the Free Pascal compiler for the following platforms: Linux i386, FreeBSD i386, Windows (Win32 console application). You may use it on your own risk, there is no warranty for anything.
Linux (i386) executable: mol2ps-latest-linux-i386.gz (approx. 81 KB)
FreeBSD (i386) executable: mol2ps-latest-freebsd-i386.gz (approx. 114 KB)
Win32 console application: mol2ps-latest-win32.zip (approx. 62 KB)
example color definition file: color.conf
]]>
1. 閫氳繃浣跨敤OBMol, OBAtom鍜孫BBond鏉ュ垱寤哄師瀛愬拰閿?/strong>
import openbabel
mol = openbabel.OBMol()
print 'Should print 0 (atoms)'
print mol.NumAtoms()
a = mol.NewAtom()
a.SetAtomicNum(6) # carbon atom
a.SetVector(0.0, 1.0, 2.0) # coordinates
b = mol.NewAtom()
mol.AddBond(1, 2, 1) # atoms indexed from 1
print 'Should print 2 (atoms)'
print mol.NumAtoms()
print 'Should print 1 (bond)'
print mol.NumBonds()
mol.Clear();
2. 閫氳繃OBConversion鏉ヨ鍙栧垎瀛? 騫惰緭鍑轟笉鍚屾牸寮忔枃浠舵垨瀛楃涓插?/strong>
import openbabel
obConversion = openbabel.OBConversion()
obConversion.SetInAndOutFormats("smi", "mdl") //璇誨彇smiles鍊? 鐒跺悗杈撳嚭mdl鍊?br />
mol = openbabel.OBMol()
obConversion.ReadString(mol, "C1=CC=CS1")
print 'Should print 5 (atoms)'
print mol.NumAtoms()
mol.AddHydrogens()
print 'Should print 9 (atoms) after adding hydrogens'
print mol.NumAtoms() //杈撳嚭鍘熷瓙涓暟
outMDL = obConversion.WriteString(mol)
3. 璁$畻fp鍊?/strong>
import pybel
smiles = ['CCCC', 'CCCN']
mols = [pybel.readstring("smi", x) for x in smiles] # Create two molecules from the SMILES
fps = [x.calcfp() for x in mols] # Calculate their fingerprints
print fps[0].bits, fps[1].bits
print fps[0].fp[0]
mol2 = pybel.readstring('smi', 'c2ccc1ccccc1c2')
fp2 = mol2.calcfp("FP4")
print fp2
print fp2.bits
mol3 = pybel.readstring('smi', 'C1CCCCC1')
fp3 = mol3.calcfp()
print fp3.__or__(fp2) //璁$畻鐩鎬技搴﹀?br />
4. 璇誨彇sdf鏂囦歡
#encoding=utf-8
import pybel
for mymol in pybel.readfile("sdf", "structures_all.sdf"):
fp = mymol.calcfp("FP2")
print fp
5. 杈撳嚭txt鏂囦歡鍜宻df鏂囦歡
import org.openbabel.OBConversion;
import org.openbabel.OBMol;
import org.openbabel.OBSmartsPattern;
public class Test {
public static void main(String[] args) {
// Initialise
System.loadLibrary("openbabel_java");
// Read molecule from SMILES string
OBConversion conv = new OBConversion();
OBMol mol = new OBMol();
conv.SetInFormat("smi");
conv.ReadString(mol, "C(Cl)(=O)CCC(=O)Cl");
// What are the indices of the carbon atoms
// of the acid chloride groups?
OBSmartsPattern acidpattern = new OBSmartsPattern();
acidpattern.Init("C(=O)Cl");
long t1 = System.currentTimeMillis();
boolean flag = acidpattern.Match(mol);
long t2 = System.currentTimeMillis();
System.out.println("Cost time:" + (t2-t1) + "ms");
System.out.println(flag);
}
}