Thanks Neeraj and Albino for the reply, but my problem is visualizing a small chemical compound. I want how to know these software do it, how they identify where a chain start and how ring(or cyclic) structure(like benzene etc) is identified?
Simply these softwares have cached libraries in which the most common bond types are described. I don't know about the mol2 format, pdb file format has a tag "CONECT" to describe the specific connectivity of exogenous molecules.
The BOND block of mol2 or SD files defines which atoms are bonded to which and in what way (single, double, triple, aromatic etc.)
More broadly most file formats explicitly define connectivity;. Unfortunately, XYZ (and sometimes PDB) format files do not define the connectivity, the file reader is left to determine which atoms are bonded to which based only on element and inter- atomic distance. Connectivity CAN be specified in a PDB format file using the CONECT tag, but this is not required for small molecules in protein-ligand complexes.
Predicting ring like structure from 3D coordinates is a very complex process. There are lots of literature on this problem. Most of the visualization software uses their own set of rules such as bond-length or uses standard library for representation to define a ring. As per my opinion you can implement breadth-first ring finding algorithm for finding ring like structure in a 3D coordinate system. Here is the paper link: http://pubs.acs.org/doi/abs/10.1021/ci00015a002