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.